2013-06-19 200 views
0

非常多,我試圖找到一種方法,您可以在一個應用程序中的圖像上同時縮放和旋轉。用兩個手指旋轉和縮放?

我發現這個代碼,命令我把它放到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; 

現在只用兩個手指旋轉的,但我需要能夠在同一時間,以放大也使用兩個手指。我嘗試了一切,但我只是不確定什麼是錯的或如何從這裏走。

無論如何,地圖應用程序做了類似的地方,你可以放大地圖並同時旋轉它,這就是我想要在我的應用程序中的圖像上完成的。

無論如何,從這一點我該怎麼做?

謝謝!

回答

1

UIPinchGestureRecognizerUIRotationGestureRecognizer添加到您的視圖,設置它們的代表並實現下面的委託功能。

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

應該這樣做。