-1

In iPhone App I want add functionality to (imageview or webview or other control) zoom in/out an image with pinch gesture.

10

2 Answers 2

3

You can use a UIScrollView for that.

Add a UIImageView to the UIScrollViewand configure the UIScrollView for zooming via its propertys. Check the UIScrollview Class Reference - Zooming and Panning Section

Edit: Good point by Mike: Check the PhotoScrollersample code by Apple, too

1
  • 1
    Also see the Apple "PhotoScroller" sample code which contains an ImageScrollView class which does this. It also handles some special cases like rotation that might interest you. Jun 5, 2012 at 7:15
0

Please refer to this code. I have used it in one of my apps so it works:

- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer {

    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
    recognizer.scale = 1;
}

Also don't forget to add Pinch gesture recognizer to your imageView.

enter image description here

Hope this helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.