用两个手指旋转和缩放



我正试图找到一种方法,可以在应用程序中的图像上同时缩放和旋转。

我发现了这段代码,指示我把它放入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;

现在这只适用于用两个手指旋转,但我需要能够使用两个手指同时缩放。我已经尝试了一切,但我只是不确定是什么错了,或者如何从这里走。

无论如何,地图应用做了类似的事情你可以在地图上放大并同时旋转它这就是我试图在我的应用程序中的图像上完成的。

不管怎样,从现在开始我该怎么办?

谢谢!

将UIPinchGestureRecognizer和urotationgesturerecognizer添加到你的视图中,设置它们的委托并实现下面的委托函数

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

应该可以了

最新更新