This is the only solution that I found to work flawless. It includes double tap and two finger gestures to zoom in and out. http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
UIImageView in UIScrollView, zooming is jittery
-
01-06-2022 - |
Question
I have a UIImageView in a UIScrollview. I used the instructions in Apple's docs.
I set minimum and maximum zoom scales. (0.5 and 6.0). I set the delegate to self.
I returned the image view in viewForZoomingInScrollView. However I don't know what to do in scrollViewDidEndZooming.
The result I am having is a jittery zoom and not consistent. It is just not behaving like the photo gallery app.
Am I missing something?
Solution 3
OTHER TIPS
//create imageview with pinchGesture
CGRect myImageRect = CGRectMake(17, 95, 285, 130);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:picture]];
myImage.userInteractionEnabled = YES;
UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePinch:)];
pgr.delegate = self;
[myImage addGestureRecognizer:pgr];
[scrollview addSubview:myImage];
// handlepinch: method
- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
}
Before that add in .h file
Hope it will useful for you...
Set your ImageView scaling contentMode to be UIViewContentModeCenter and zoom out (if needed) on load. Set the starting zoom scale when you have the image ready by doing something like this :
//Min scale is how much ever it takes to fit the image in the view
CGRect scrollViewFrame = self.scrollView.frame;
CGFloat scaleWidth = scrollViewFrame.size.width / self.imageView.image.size.width;
CGFloat scaleHeight = scrollViewFrame.size.height / self.imageView.image.size.height;
CGFloat minScale = MIN(scaleWidth, scaleHeight);
self.scrollView.minimumZoomScale = minScale;
self.scrollView.zoomScale = minScale;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow