user1881612
user1881612

Reputation:

How to remove gesture after implementing UIGestureRecognizer

I am using PinchGestureRecognizer and RotationGestureRecognizer both working fine. The code is as follows:

- (IBAction)pinchDetected:(UIPinchGestureRecognizer *)recognizer {

    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
    recognizer.scale = 1;
}


-(IBAction)rotationDetected:(UIRotationGestureRecognizer *)recognizer
{
    recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
    recognizer.rotation = 0;
}

with this code I am able to pinch as well as rotate my view. but on "RESET" button click I want to set my view's frame as it was before pinching or rotating.

for that I am using

[viewTwo setFrame:CGRectMake(80.0f, 65.0f, 160.0f, 101.0f)];

but my frame does not set.

so How can I set my view's frame again as it was before pinching and zooming?

Upvotes: 2

Views: 297

Answers (2)

Fogmeister
Fogmeister

Reputation: 77661

You are not changing the frame with your gesture recognisers.

You need to assign the transform back to the identity.

recognizer.view.transform = CGAffineTransformIdentity;

Upvotes: 4

CodaFi
CodaFi

Reputation: 43330

Frame and transform are applied to a view in two completely separate ways (where frame is the smallest rectangle that fits a view, and transform is a representation of the underlying 2-D matrix of the view). If you wish to return to the size the view was previously, assign recognizer.view.transform to CGAffineTransformIdentity.

Upvotes: 0

Related Questions