2011-01-29 117 views
1

我正在使用下面的代碼嘗試讓我的識別器在狀態結束後繼續旋轉。無論我在CGAffineTransformRotate中設置了多少值,它似乎只有一次旋轉。一旦狀態結束,我如何獲得旋轉手勢以繼續旋轉?

任何洞察力或建議,將不勝感激。

謝謝。

if([(UIRotationGestureRecognizer*)recognizer state] == UIGestureRecognizerStateEnded) 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:6.55]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, 1000000000); 
    [UIView commitAnimations]; 
} 
+0

概念校正選項:您不能設置旋轉值超高,並且具有相當於多次旋轉。您正在創建一個仿射變換,它是一個固定矩陣。它不知道怎麼說「繼續前進」 - 你創建的旋轉基本上是「mod 360度」。請參閱@thelaws'的更好技術的答案。 – 2011-01-30 00:35:46

回答

4

你可能想嘗試使用CABasicAnimation

- (void)rotate { 

[CATransaction begin]; 
[CATransaction setValue:[NSNumber numberWithFloat:2.0] forKey:kCATransactionAnimationDuration]; 

CABasicAnimation *animation; 
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
animation.fromValue = [NSNumber numberWithFloat:0.0]; 
animation.toValue = [NSNumber numberWithFloat:2 * M_PI]; 
animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear]; 
animation.delegate = self; 
[recognizer.layer addAnimation:animation forKey:@"rotationAnimation"]; 

[CATransaction commit]; 
} 

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)finished { 
if (finished) 
    [self rotate]; 
} 

這將導致旋轉繼續下去,直到你指定要刪除的動畫。

有更多資料,並在CABasicAnimation類參考

+0

這是一切都很好,但它會成爲一個噩夢,建立一個自然的感覺旋轉,哈哈。雖然贊成努力。 – 2011-01-29 23:53:27