-1

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

halfer
  • 19,824
  • 17
  • 99
  • 186
ios
  • 6,134
  • 20
  • 71
  • 103

2 Answers2

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

Pfitz
  • 7,336
  • 4
  • 38
  • 51
  • 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. – Mike Weller Jun 05 '12 at 07: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.

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216