Zoom To Pinch In UIView

Discussion in 'iOS Programming' started by loon3y, Oct 24, 2011.

  1. loon3y, Oct 24, 2011
    Last edited by a moderator: Oct 24, 2011

    loon3y macrumors 65816


    Oct 21, 2011
    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] 
        [[self view] addGestureRecognizer:twoFingerPinch];


    - (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;
  2. chown33 macrumors 604

    Aug 9, 2009
    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.

Share This Page