Why CAAnimation Rotation is returning to previous

2019-01-29 12:23发布

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条回答
2楼-- · 2019-01-29 12:47

Add this line before calling addAnimation..

rotation.fillMode = kCAFillModeForwards;
查看更多
登录 后发表回答