Iphone如何连续旋转图像30秒并以180度停止

Iphone如何连续旋转图像30秒并以180度停止,iphone,animation,ios6,xcode4.5,Iphone,Animation,Ios6,Xcode4.5,到目前为止,我有这个。我希望图像旋转大约30秒,然后停下来,然后面向另一个方向 编辑。更改了代码。我有这个,但它会旋转,不会停止180度。我想让它旋转几次,然后朝相反的方向停下来 CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"]; animation.duration = 0.60;//animation.duration = 0

到目前为止,我有这个。我希望图像旋转大约30秒,然后停下来,然后面向另一个方向

编辑。更改了代码。我有这个,但它会旋转,不会停止180度。我想让它旋转几次,然后朝相反的方向停下来

       CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
  animation.duration = 0.60;//animation.duration = 0.60;
  animation.repeatCount = 1;//animation.repeatCount = 1000ˆ

//#warning remove comment brackets below

  animation.keyTimes = [NSArray arrayWithObjects:
                        [NSNumber numberWithFloat:0.0],
                        [NSNumber numberWithFloat:1.0], nil];

  animation.values = [NSArray arrayWithObjects:
                      [NSNumber numberWithFloat:0.0],
                      [NSNumber numberWithFloat:(degrees / 180)*M_PI], nil];

  animation.fillMode = kCAFillModeForwards;
如何在图像仍旋转180度的情况下停止动画

怎么样

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.delegate = self;
animation.autoreverses = YES;
animation.repeatDuration = 30;
animation.duration = 1.0;
animation.fromValue = [NSNumber numberWithFloat:-degreeToRadian(180)];
animation.toValue=[NSNumber numberWithFloat:degreeToRadian(180)];
[self.button.layer addAnimation:animation forKey:@"animation"];
然后添加一个委托方法

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
   self.button.transform = CGAffineTransformMakeRotation(degreeToRadian(180));
}

我希望这是您想要的。

图像位于UIButton中。我从未对层使用过动画,但您设置为1.1的duration属性不是要设置为30秒的值吗?30秒:添加动画后,使用[self-performSelector:@selector(funct)with Object:nil afterDelay:30];并调用[yourview.layer removeAllAnimations];在funct(selector)中,这应该是可行的。我已经想出了上面的方法,但它不会在180度时停止。我的公式错了吗。