简体   繁体   English

用两根手指旋转和缩放?

[英]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: 我发现以下代码指示我将其放入touchesMoved方法中:

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! 谢谢!

Add UIPinchGestureRecognizer and UIRotationGestureRecognizer to your view, set their delegates and implement the below delegate function. UIPinchGestureRecognizerUIRotationGestureRecognizer添加到视图中,设置其委托并实现以下委托函数。

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

That should do it. 那应该做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM