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

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
The following zooms to scale perfectly, but no bounce effect like UIScrollView delegate. Any ideas on how to manually create the bounce effect?

Code:
-(void)pinchGestureRecognized:(UIPinchGestureRecognizer*)recognizer
{
        if (recognizer.state == UIGestureRecognizerStateBegan) {
            lastScale = recognizer.scale;
        }
    
        if (recognizer.state == UIGestureRecognizerStateBegan || recognizer.state == UIGestureRecognizerStateChanged)
        {
            CGFloat currentScale = [[recognizer.view.layer valueForKeyPath:@"transform.scale"] floatValue];
    
            const CGFloat kMinScale = 0.75;
            const CGFloat kMaxScale = 1.00;
    
            CGFloat newerScale = 1 - (lastScale - recognizer.scale);
            newerScale = MIN(newerScale, kMaxScale/currentScale);
            newerScale = MAX(newerScale, kMinScale/currentScale);
            CGAffineTransform transform = CGAffineTransformScale(recognizer.view.transform, newerScale, newerScale);
            recognizer.view.transform = transform;
    
            lastScale = recognizer.scale;
        }
}
 

Reason077

macrumors 68040
Aug 14, 2007
3,606
3,644
You can add a bounce effect pretty easily using [UIView animateWithDuration...]. If the user goes over the limit you define, just animate it back to the limit value when the pinch gesture ends.

If you want to get more advanced, you can also add resistance, etc.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.