LK.
LK.

Reputation: 4569

Pinch zoom without UIScrollView based control

Is there an "accepted" way of performing (pinch) zoom on a view that is not based on UIScrollView?

Upvotes: 1

Views: 1464

Answers (3)

Shefali Soni
Shefali Soni

Reputation: 249

This code helps to zoom UIImageView without using UIScrollView.

-(void)HandlePinch:(UIPinchGestureRecognizer*)recognizer{
    if ([recognizer state] == UIGestureRecognizerStateEnded) {
        NSLog(@"=======Scale Applied===========");
        if ([recognizer scale]<1.0f) {
            [recognizer setScale:1.0f];
        }
        CGAffineTransform transform = CGAffineTransformMakeScale([recognizer scale],  [recognizer scale]);
        imgView.transform = transform;
    }
}

Upvotes: 0

rekle
rekle

Reputation: 2375

If you are working in iPhone OS 3.2 (for the iPad) or iOS 4 for the iPhone 4, you can use the UIPinchGestureRecognizer class to detect pinch gestures.

Upvotes: 0

warrenm
warrenm

Reputation: 31782

There's a code sample by Erica Sadun that does the math for treating touch events as scale/rotate/translate transforms that you can probably borrow from. Basically, it sounds like you want to apply a scaling affine transform. This code doesn't include the niceties of "bouncing" the view when you reach the edges of the content, so you'll have to do that yourself.

Full disclosure: I haven't done this in almost a year. It's likely that there are frameworks now that include much more straightforward support for this feature.

Upvotes: 1

Related Questions