HomeХобби и стильRelated VideosMore From: profgustin

iOS 5 - Pinch Gestures

37 ratings | 12815 views
Demonstrates how to add a pinch gesture to a view. In this example it zooms an image in and out. Uses UIGestureRecognizer and CGAffineTransform. Photo Credits: Robert Kohlhuber - http://www.istockphoto.com/stock-photo-12953897-trapped-manga-girl.php
Html code for embedding videos on your blog
Text Comments (13)
Piyush Vaish (3 years ago)
Thanks a bunch. Helped. But why did you do lastScaleFactor*factor in case of Zoom Out?
Chen Jiling (4 years ago)
Nice tutorial. But lastScaleFactor is a local variable, It doesn't make scene to change it in the end of the handlePinch. Below codes should work: CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];          if (factor >1) { //zoom in         _imageView.transform=CGAffineTransformMakeScale(1+ (factor -1), 1+ (factor -1));              }else { //zoom out         _imageView.transform=CGAffineTransformMakeScale(1* factor , 1* factor );     }
bato ostaev (4 years ago)
th so mach :)
Ali Salem (5 years ago)
how can i scroll a picture while am zooming in/out ? 
Tom Hutchinson (4 years ago)
I added a scrollview and connected the gesture to that
Ali Salem (5 years ago)
- (IBAction)handlePinch:(UIGestureRecognizer *)sender {          NSLog(@"Pinched");     CGFloat lastScaleFactor =1;     CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];          if (factor >1) { //zoom in         _imageView.transform=CGAffineTransformMakeScale(lastScaleFactor + (factor -1), lastScaleFactor + (factor -1));              }else { //zoom out         _imageView.transform=CGAffineTransformMakeScale(lastScaleFactor * factor , lastScaleFactor * factor );     }          if (sender.state==UIGestureRecognizerStateEnded) {         if (factor>1)                          lastScaleFactor += (factor-1);             else             lastScaleFactor *= factor;              }           }
Ali Salem (5 years ago)
Thank you , Super Like =)
jon millar (5 years ago)
FINALLY someone who correctly explained this THANK YOU SOO MUCH For ages I could not get pinch and zoom to work correctly, but this works a treat, Thanks thanks thanks!! Jon :)
Kin Kin Pro (5 years ago)
You rock!
BukkoGamer (5 years ago)
I just wanted to comment and say your method of explaining and teaching this was very clear and helped make sense of things that I was having an issue with understanding as well as also learning some more tips and tricks with Xcode. Overall thank you for posting this video it helped a lot!
Shiva Vattem (6 years ago)
gud oneeee
priyadas haridas (6 years ago)
Nice tut dear !
burlponygames (6 years ago)
I'm just starting out with Macs and Xcode. This tutorial made it easier for me to understand then the other ones I've found. Think you need to move CGFloat lastScaleFactor =1; from the action though. It also made it easy for me to add a Max and Min Zoom. Thank you so much.

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.