Zoom To Pinch In UIView

Joined
Oct 11, 2011
Messages
46
Reaction score
0
Points
6
Your Mac's Specs
13" MacBook Pro 2.4 GHz 8 GB Ram 250 GB HD, iPhone 4/S 64 GB, iPhone 3GS 16 GB, iPad 16 GB Wi-Fi
i added zoom to pinch on the UIView in my iPhone app. but i can't limit how much it zooms in and out. i want the limit of zooming out to the size of the original view. and i want the zooming to be reasonable. can some one help me?

i added these two codes:


- (void)viewDidLoad
{
UIPinchGestureRecognizer *twoFingerPinch = [[[UIPinchGestureRecognizer alloc]
initWithTarget:self
action:mad:selector(twoFingerPinch]
autorelease];

[[self view] addGestureRecognizer:twoFingerPinch];
}




&



- (void)twoFingerPinchUIPinchGestureRecognizer *)recognizer
{
NSLog(@"Pinch scale: %f", recognizer.scale);
CGAffineTransform transform = CGAffineTransformMakeScale(recognizer.scale, recognizer.scale);
// you can implement any int/float value in context of what scale you want to zoom in or out
self.view.transform = transform;
}
 
Joined
Feb 25, 2009
Messages
2,112
Reaction score
71
Points
48
Your Mac's Specs
Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
I'd try just testing the value of the scale, if it's <1.0, then make the scale 1.0. If it's > some max value (you already printing out the scale values, find one that you like for a max), then set it to the max value.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top