Why CAAnimation Rotation is returning to previous

2019-01-29 13:05发布

问题:

I am using CAKeyFrameAnimation to do rotation of an arrow image.

Problem is that the imageview is returning back to the previos state after animation.

Code:

CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation]; rotation.duration = 0.55; rotation.cumulative = TRUE; rotation.removedOnCompletion = NO; if (isFlipRight) { rotation.values = [NSArray arrayWithObjects: [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 0.0f, 1.0f, 0.0f)], [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f)],nil];

} else { rotation.values = [NSArray arrayWithObjects: [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f)], [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 0.0f, 1.0f, 0.0f)],nil];

}

[[arrowImageView layer] addAnimation:rotation forKey:@"transform"];

回答1:

Add this line before calling addAnimation..

rotation.fillMode = kCAFillModeForwards;