我想基于CGPath设置CALayer的位置动画,但我想向后播放它。
有没有办法让路径向后动画,或者反转CGPath?
答案 0 :(得分:29)
animation.speed = -1;
答案 1 :(得分:4)
这可能不是最佳解决方案,但它对我有用。我告诉动画自动反转,然后开始中途。但是为了防止它再次动画,我需要提前终止它。
- (void) animate {
CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = path;
pathAnimation.duration = 15.0;
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.timeOffset = pathAnimation.duration;
pathAnimation.autoreverses = YES;
NSString * key = @"pathAnimation";
[animatedView.layer addAnimation:pathAnimation forKey:key];
[NSTimer scheduledTimerWithTimeInterval:pathAnimation.duration target:self selector:@selector(endAnimation:) userInfo:key repeats:NO];
}
- (void) endAnimation:(NSTimer *)timer {
[animatedView.layer removeAnimationForKey:timer.userInfo];
}
如果存在更好的方法,我想知道。