The method - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView isn't called [duplicate] - iphone

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
The zoom for uiscrollview isn’t working
I posted a question yesterday, because the zoom for the UIScrollView isn't working. When pressing on a button, a UIScrollView appears, that contains an UIImage, but the problem is that I can't zoom by clicking or double-clicking on the image. I made a debug and the method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
doesn't get called. The question can be found here
Sorry for asking the same question again. Thank you in advance. I wish you all the best!

Try changing the property UserInteractionEnabled of image view to YES. May be that can help

Did u set the delegate of scrollview.First check it once...if delegate returns nil, nothing happens....so first set the delegate of UIScrollview.

Related

how to add short sounds while swiping images in uiscrollview [duplicate]

This question already has answers here:
How to add sound while UIScrollview is scrolling in iphone sdk?
(2 answers)
Closed 3 years ago.
how to add sounds in uiscrollview,while swiping different images with different sounds.
please help me.
Thanks regards
Rajan
When scrolling stop then you can check that page is changed or not. If Changed than play sound else not.
You have to use UIScrollViewDelegate methods to achieve this task you can use
scrollViewDidEndDecelerating: to achieve this with the using one ivar to store the current display position of the UIScrollView and in this method using contentOffset.x property of the UIScrollView you can achieve what you need.
Yep you need to use AVAudioPlayer to play sound.
Think this will help you.
Happy Codding :)
Enjoy Coding :)

How to scroll the UITableviewcell scroll up when the keyboard appears? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Table View scroll when text field begin editing iphone
I have loaded many UITextFields in UITableview. Maximum i have 15 UITextFields in UITableView cells. I want to move(Scroll) up the the Cell when the Keyboard/UIActionSheet(UIPickerView) appears. Please suggest/guide me any sample code to solve this problem. Thanks in advance.
You can use the sample code to take some hint.
https://github.com/michaeltyson/TPKeyboardAvoiding
I have used it in my projects as well.Hope it helps
Please try below code in -textFieldShouldBeginEditing ....
self.tblView.frame= CGRectMake(self.tblView.frame.origin.x, self.tblView.frame.origin.y, self.tblView.frame.size.width, self.tblView.frame.size.height - 190);
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:nIndex inSection:nSectionIndex];
[self.tblView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
Thanks
Check out the below link from apple documentation with complete explanation and required code
They have talked about for registering for the keyboard appear and disappear notification and alter the rect of your underlaying UIView in the notification method for more go through the below URL.
Moving Content That Is Located Under the Keyboard

how can i highlight my image view awhen user touching it? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Tasks with my UIImageView
How can i highlight my UIImageview and display a deleteButton(cross button) on top of the imageview when user touching the UIImageview?.
You need to create a IBAction that adds the cross button and wire it to the touchDown event in interface builder. You could probably make a timer that will give it a couple seconds before activating.
Option 2: read about gestureRecognizers, they are very simple and I learned them in a couple hours.
http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html <-- all about recogizers
It's pretty straight forward. Use
UILongPressGestureRecognizer
In the methods below write a code for detecting gestures and popping up a delete button.
- (void)handleGesture; //or
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;
For deleting use
- (void)removeTarget:(id)target action:(SEL)action

UIScrollView - Figuring out where the scroll will stop

I'm trying to figure out how to calculate where the scrollview will stop when a user does a swipe gesture and the scrollview goes into deceleration. I'm trying to use the delegate functions, but I can't accurately figure it out. Please help!
- (void) scrollViewDidScroll:(UIScrollView *)scrollView;
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
This thread is a bit old, but still comes up top in a search for this problem.
The UIScrollViewDelegate protocol contains the following method that tells your code where the scroll view is expected to stop...
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
The targetContentOffset parameter is an inout so if you set it to a different value, the scrollview will actually come to a stop at the offset you specify.
Unfortunately UIScrollView doesn't work this way-- there's no way to ask it up front where the deceleration ends.
Sounds complicated. The user may start scroll again while it is decelerating, stop it suddenly or what not. Maybe you can get by with just doing DidEndDecelerating, i.e just detecting the position when the scrolling is over?
It should be simple math. The contentOffset property of the scrollview is updated each time scrollViewDidScroll is called. You only need to save the vector between two positions and the time to get at least a descent end-position of the deceleration.
Note that the user can stop the deceleration any time by tapping on the scrollview as Jaanus pointed out.
There is a variable for the current acceleration that is kept in the UIScrollView implementation but using that as a solution is impossible because you can't compile the code for a device.

How do I choose the correct view for zooming with multiple UIScrollView objects in a view (iPhoneSDK obj-C)?

I have added several UIScrollViews as subviews of a single UIView and set the frames so that each one is clearly visable. I set scrollEnabled to YES and set the contentSize larger than the bounds/frame. I do this in a for loop, and with each pass of the loop I release the UIScrollView (though the object is still stored because it has been subviewed into the UIView). This works well for being able to scroll around the imageView stored in each particular UIScrollView but I cannot for the life of me figure out how to get the zoom to work. I included the in the interface. Here are the methods I have tried for choosing the correct view for zooming:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [[myView subviews] objectAtIndex:pageNum];
}
and
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [myView viewWithTag:pageNum];
}
neither seems to work. The weird part is that scrolling works fine. I can't even get the viewForZooming method to get called at all if I put in an NSLog call. Any ideas? I think I've lost all my hair from getting frustrated with this.
Edit: Thanks a lot cduhn! All I needed was that little bump, I had forgotten to set the scrollView delegate to self... I've been working with various apps that take advantage of UIScrollView for months now and been using the delegate correctly and this most recent one I don't know where my brain went.
However, you do not need to override the scrollViewDidEndZooming:withView:atScale:, the delegate will call that no matter what after a zoom.
Also, after a little tweeking this worked:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [[[myView viewWithTag:pageNum] subviews] objectAtIndex:0];
}
This simply calls the scrollView inside View container and then gets the UIImage inside of that... works well.
It sounds like you may not have set the delegate property on your UIScrollViews to point at the object that implements viewForZoomingInScrollView:
Also note this snippet from the UIScrollView Class Reference:
For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:; in addition, the maximum (maximumZoomScale) and minimum ( minimumZoomScale) zoom scale must be different.
Finally, a word of warning: Be careful when accessing the subviews of UIScrollView. Your subviews are not alone in there. UIScrollView adds its own UIImageViews as subviews of itself to implement its scrollbar UI. So code like this...
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [[myView subviews] objectAtIndex:pageNum];
}
... may not do what you expect.