Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

loon3y

macrumors 65816
Original poster
Oct 21, 2011
1,235
126
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:


Code:
- (void)viewDidLoad
{
    UIPinchGestureRecognizer *twoFingerPinch = [[[UIPinchGestureRecognizer alloc] 
                                                 initWithTarget:self 
                                                 action:@selector(twoFingerPinch:)] 
                                                autorelease];
    
    [[self view] addGestureRecognizer:twoFingerPinch];
}




&



Code:
- (void)twoFingerPinch:(UIPinchGestureRecognizer *)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;
}
 
Last edited by a moderator:
Have you tried using min and max functions on the recognizer's scale property, before turning it into a view transform?

fmin() and fmax() are standard C functions. Look them up in Xcode's documentation.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.