我正在使用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; } }
以上代码只是想法.它没有测试