Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView and UIScrollView zooming

Do I actually need a UIPinchGestureRecognizer inside a UIScrollView to have the pinch working? If yes how do I do it? I am trying to implement what flipboard has, where it basically zooms in an image and have the scroll capability after zooming in. How do I do that?

UPDATE:

Here's some code that I have which doesn't call the scroll view delegate

CGRect imgFrame; imgFrame.size.width = originalImageSize.width; imgFrame.size.height = originalImageSize.height; imgFrame.origin.x = imageOriginPoint.x; imgFrame.origin.y = imageOriginPoint.y;  NSData *data = [request responseData]; UIImage * image = [UIImage imageWithData:data]; imageView = [[UIImageView alloc] initWithImage:image]; [imageView setUserInteractionEnabled:YES]; [imageView setBackgroundColor:[UIColor clearColor]]; [imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; [imageView setFrame:CGRectMake(0, 0, imgFrame.size.width, imgFrame.size.height)];  UIScrollView * imgScrollView = [[UIScrollView alloc] initWithFrame:imageView.frame]; imgScrollView.delegate = self; imgScrollView.showsVerticalScrollIndicator = NO; imgScrollView.showsHorizontalScrollIndicator = NO; [imgScrollView setScrollEnabled:YES]; [imgScrollView setClipsToBounds:YES]; [imgScrollView addSubview:imageView]; [imgScrollView setBackgroundColor:[UIColor blueColor]]; [imgScrollView setMaximumZoomScale:1.0]; 
like image 964
adit Avatar asked Jan 17 '12 08:01

adit


People also ask

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .


1 Answers

All you need to do is add your UIImageView (or any view you want to zoom) inside your UIScrollView.

Set your maximumZoomScale on your UIScrollView to any value higher than 1.0f.

Set yourself as the delegate of your UIScrollView and return the UIImageView in the viewForZooming delegate method.

That's it. No pinch gesture needed, no nothing. UIScrollView handles pinch zooming for you.

like image 150
Ignacio Inglese Avatar answered Sep 23 '22 09:09

Ignacio Inglese