以降低的速度旋转UIView超过360度

时间:2013-01-09 17:15:29

标签: iphone ios objective-c core-animation calayer

我有一个UIView,我希望在给定的T持续时间内围绕其中心点旋转N个旋转。并且旋转速度应该逐渐减小。 (如旋转轮)。我有下面的代码,它不能正常工作。

   float T = 5; // 5 seconds
   float rotations = 10;
   //_containerView is the view to be rotate

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:T];
    [UIView setAnimationRepeatCount:0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    CGAffineTransform t = CGAffineTransformRotate(_containerView.transform, (2*M_PI*rotations + 0));
    _containerView.transform = t;
    [UIView commitAnimations];

1 个答案:

答案 0 :(得分:0)

#define StartAnimation(duration) [UIView beginAnimations:nil context:NULL];    \
[UIView setAnimationDuration:duration];       \
[UIView setAnimationRepeatAutoreverses:NO];   \
[UIView setAnimationRepeatCount:0]

#define StopAnimation [UIView commitAnimations]

定义这些宏并使用

StartAnimation(<time>)
//your code
StopAnimation