ios – 使用CABasicAnimation多次旋转UIImageView

前端之家收集整理的这篇文章主要介绍了ios – 使用CABasicAnimation多次旋转UIImageView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用CABasicAnimation顺时针旋转UI ImageView 90度,但是在最初90度旋转之后,我需要将其从其位置再旋转90度.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 10;
animation.additive = YES;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.fromValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(0)];
animation.toValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(90)];
[_myview.layer addAnimation:animation forKey:@"90rotation"];

使用上面的代码最初起作用,图像保持在90度角.如果我再次打电话给它,使其旋转90度,则动画将通过跳回到0并旋转90度,而不是90到180度.

我的印象是animation.additive = YES;将会使进一步的动画以当前状态为起点.

有任何想法吗?

解决方法

通过角度增量值查看我的代码
static int imgAngle=0;
- (void)doAnimation
{
  CABasicAnimation *animation = [CABasicAnimation   animationWithKeyPath:@"transform.rotation.z"];
   animation.duration = 5;
  animation.additive = YES;
  animation.removedOnCompletion = NO;
  animation.fillMode = kCAFillModeForwards;
  animation.fromValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(imgAngle)];
  animation.toValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(imgAngle+90)];
 [self.imgView.layer addAnimation:animation forKey:@"90rotation"];

  imgAngle+=90;
  if (imgAngle>360) {
      imgAngle = 0;
  }
}

以上代码只是想法.它没有测试

原文链接:https://www.f2er.com/iOS/335229.html

猜你在找的iOS相关文章