【问题标题】:Iphone-How to rotate image continuously for 30 secs and stop at 180 degreesIphone-如何连续旋转图像30秒并停在180度
【发布时间】:2013-02-06 09:27:39
【问题描述】:

到目前为止我有这个。我希望图像旋转大约 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 度的情况下停止动画。

【问题讨论】:

  • 图片在 UIButton 中。
  • 我从来没有为图层使用过动画,但是您设置为 1.1 的持续时间属性不是您要设置为 30 秒的值吗?
  • 30 秒:添加动画后,使用 [self performSelector:@selector(funct) withObject:nil afterDelay:30];并调用 [yourview.layer removeAllAnimations];在函数(选择器)中,这应该可以工作。

标签: iphone animation ios6 xcode4.5


【解决方案1】:

怎么样

    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));
}

我希望这是你想要的。

【讨论】:

  • 我已经想出了上面的方法,但它不会停止在 180 度。我的公式是不是错了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-15
  • 2013-04-22
  • 1970-01-01
  • 2011-11-19
相关资源
最近更新 更多