2011-01-29 115 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