views:

138

answers:

1

Hello all, I want to rotate the uiimageview also scale the image view so how do i detect touch gesture that user is scaling or user is rotating?

+1  A: 

Beginning in iOS 3.2, Apple introduced the use of UIGestureRecognizer's. The two that you would be interested in are UIPinchGestureRecognizer and UIRotationGestureRecognizer. To use a pinch gesture you could do the following:

- (void)viewDidLoad {
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
    [imageView addGestureRecognizer:pinch];
    [pinch release];
}

- (void)handlePinchGesture:(UIGestureRecognizer *)sender {
    NSLog(@"New Scale: %f", sender.scale);
}

You could do something similar for the UIRotationGestureRecognizer then.

rickharrison
how do i scale imageview? i mean how do i get points?
Rahul Vyas
NSLog(@"New Scale: %f", sender.scale); It's also gives error while compiling like this "error: request for member 'scale' in something not a structure or union"
Rahul Vyas
@rickharrisonI want to do it without using UIGestureRecognizer is there a way to do both on touchMoved?
Rahul Vyas
You can do it in touchMoved, but it will be more complicated. You will need to get the locations of the touch and create a bounding box for those touches. Then you can scale the image view based on that bounding rectangle.
rickharrison
could you please tell me how it can be done? it might be complicated but it's not impossible....
Rahul Vyas