我希望能够基于CGPath动画CALayer的位置,但我想要反向播放。
是否有任何方法可以反向动画路径,或反转CGPath?
我希望能够基于CGPath动画CALayer的位置,但我想要反向播放。
是否有任何方法可以反向动画路径,或反转CGPath?
animation.speed = -1;
?
这可能不是最好的解决方案,但对我有效。我告诉动画自动反转,然后从一半开始它。但为了防止它再次动画化,我需要提前终止它。
- (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];
}