SimplyKiwi
SimplyKiwi

Reputation: 12444

Rotate and Zoom with two fingers?

Pretty much I am trying to find a way where you can zoom and rotate at the same time on an image in an app.

I have found this code that instructs me to put it into the touchesMoved method:

UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
CGPoint previousPoint1 = [touch1 previousLocationInView:nil];
CGPoint previousPoint2 = [touch2 previousLocationInView:nil];
CGFloat previousAngle = atan2 (previousPoint2.y - previousPoint1.y, previousPoint2.x - previousPoint1.x);

CGPoint currentPoint1 = [touch1 locationInView:nil];
CGPoint currentPoint2 = [touch2 locationInView:nil];
CGFloat currentAngle = atan2 (currentPoint2.y - currentPoint1.y, currentPoint2.x - currentPoint1.x);

transform = CGAffineTransformRotate(transform, currentAngle - previousAngle);
self.view.transform = transform;

Now that is only for rotating with two fingers but I need to be able to zoom at the same time too using two fingers. I have tried everything but I am just not sure what is wrong or how to go from here.

Anyway, the maps application does something similar where you can zoom in on the map and rotate it at the same time and that is what I am trying to accomplish on an image in my app.

Anyways, what do I do from this point?

Thanks!

Upvotes: 0

Views: 263

Answers (1)

Adithya
Adithya

Reputation: 4705

Add UIPinchGestureRecognizer and UIRotationGestureRecognizer to your view, set their delegates and implement the below delegate function.

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
   return YES;
}

That should do it.

Upvotes: 1

Related Questions