0
我有一個很奇怪的問題,我在我的應用程序中實現UIRotationGestureRecognizer來旋轉圖像。我的問題是,有時當你開始旋轉圖像時,它會跳到另一個手指。 示例:我用一根手指拖動圖像,之後用第二根手指開始旋轉,但圖像移至第二根手指。這是正常的嗎?它可以修復嗎? 我使用的代碼是:UIRotationGestureRecognizer
if([recognizer state] == UIGestureRecognizerStateEnded) {
prevRotation = 0.0;
return;
}
CGFloat newRotation = 0.0 - (prevRotation - [recognizer rotation]);
CGAffineTransform currentTransformation = image.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);
image.transform = newTransform;
prevRotation = [recognizer rotation];
我試圖拯救中心的最後一個位置,並再次應用它,但它不工作要麼,像這樣:
lastPoint=image.center;
if([recognizer state] == UIGestureRecognizerStateEnded) {
prevRotation = 0.0;
return;
}
CGFloat newRotation = 0.0 - (prevRotation - [recognizer rotation]);
CGAffineTransform currentTransformation = image.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);
image.transform = newTransform;
prevRotation = [recognizer rotation];
image.center=lastPoint;
您的拖動是從UIPanGestureRecognizer? – borrrden 2012-07-23 06:57:44
不,如果觸摸位於視圖內,我的拖動是檢測,如果它位於touchesMoved,則將我的圖像中心更改爲觸摸。 – user1179587 2012-07-23 16:57:26
您可能只是在移動觸摸時進行任何操作。你無法做到這一點,因爲那樣會用手指或跳到那個手指。您需要跟蹤屏幕上有多少個手指,並且不要在兩個手指向下時拖動,或者計算兩個手指的平均值。或者節省一些麻煩並使用UIPan。 – borrrden 2012-07-23 23:36:48