在本教程中,我找到了如何在视频中制作动画CALayer: http://www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlays-and-animations-to-videos
CABasicAnimation *animation
=[CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration=3.0;
animation.repeatCount=5;
animation.autoreverses=YES;
// animate from fully visible to invisible
animation.fromValue=[NSNumber numberWithFloat:1.0];
animation.toValue=[NSNumber numberWithFloat:0.0];
animation.beginTime = AVCoreAnimationBeginTimeAtZero;
[overlayLayer1 addAnimation:animation forKey:@"animateOpacity"];
但是当我想动画CALayer的动作时它不起作用:
animation.keyPath = @"position.x";
或
animation.keyPath = @"position.y";
是否可以为CALayer的动作设置动画?
答案 0 :(得分:0)
尝试使用此密钥路径:
animation.keyPath = @"transform.translation.x";
答案 1 :(得分:0)
任何动画都将在视频的时间轴上进行解释,而不是实时,因此您应该:
将动画的beginTime属性设置为AVCoreAnimationBeginTimeAtZero而不是0(CoreAnimation替换为CACurrentMediaTime);
将动画上的removedOnCompletion设置为NO,这样它们就不会自动删除;