Objective c AVVideoCompositionCoreAnimationTool未添加所有Calayer
好吧,这件事把我难住了。如果您需要,我很乐意发布其他代码,但我认为这已经足够了。我一辈子都搞不明白为什么事情会出差错。我正在使用AVVideoCompositionCoreAnimationTool将包含图像的CALayers添加到合成中。我创建了一个包含所有要添加的注释的NSArray(请参见下面的界面),然后使用枚举器将它们添加到动画层。据我所知,不管数组中有多少注释,最后输出的视频中只有最后一个循环添加的注释。有人能发现我遗漏了什么吗 这是注释的界面Objective c AVVideoCompositionCoreAnimationTool未添加所有Calayer,objective-c,macos,avfoundation,calayer,avassetexportsession,Objective C,Macos,Avfoundation,Calayer,Avassetexportsession,好吧,这件事把我难住了。如果您需要,我很乐意发布其他代码,但我认为这已经足够了。我一辈子都搞不明白为什么事情会出差错。我正在使用AVVideoCompositionCoreAnimationTool将包含图像的CALayers添加到合成中。我创建了一个包含所有要添加的注释的NSArray(请参见下面的界面),然后使用枚举器将它们添加到动画层。据我所知,不管数组中有多少注释,最后输出的视频中只有最后一个循环添加的注释。有人能发现我遗漏了什么吗 这是注释的界面 @interface Annotati
@interface Annotation : NSObject// <NSCoding>
@property float time;
@property AnnotationType type;
@property CALayer *startLayer;
@property CALayer *typeLayer;
@property CALayer *detailLayer;
+ (Annotation *)annotationAtTime:(float)time ofType:(AnnotationType)type;
- (NSString *)annotationString;
@end
我想强调的是,视频输出是正确的,我确实在正确的时间得到了层的显示,只是不是所有的层。非常困惑,非常感谢您的帮助。因此,我一直在尝试找出导致此问题的原因,结果发现这是由layers hidden属性设置为YES引起的。通过将其设置为“否”,所有层都会出现,但它们从未消失。因此,我必须将动画的autoreverses属性更改为YES,并将持续时间减半 因此,我将代码更改为:
while (ann = (Annotation *)[enumerator nextObject]){
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 1.5; // TODO: Three seconds is the currently hard-coded display length for an annotation, should this be a configurable option after the demo?
animation.repeatCount = 0;
animation.autoreverses = YES; // This causes the animation to run forwards then backwards, thus doubling the duration, that's why a 3-second period is using 1.5 as duration
animation.removedOnCompletion = NO;
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
animation.beginTime = time;
// animation.beginTime = AVCoreAnimationBeginTimeAtZero;
ann.startLayer.hidden = NO;
ann.startLayer.opacity = 0.0;
ann.startLayer.masksToBounds = YES;
[ann.startLayer addAnimation:animation forKey:@"animateOpacity"];
[animationLayer addSublayer:ann.startLayer];
ann.typeLayer.hidden = NO;
ann.typeLayer.opacity = 0.0;
ann.typeLayer.masksToBounds = YES;
[ann.typeLayer addAnimation:animation forKey:@"animateOpacity"];
[animationLayer addSublayer:ann.typeLayer];
ann.detailLayer.hidden = NO;
ann.detailLayer.opacity = 0.0;
ann.detailLayer.masksToBounds = YES;
[ann.detailLayer addAnimation:animation forKey:@"animateOpacity"];
[animationLayer addSublayer:ann.detailLayer];
}
while (ann = (Annotation *)[enumerator nextObject]){
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 1.5; // TODO: Three seconds is the currently hard-coded display length for an annotation, should this be a configurable option after the demo?
animation.repeatCount = 0;
animation.autoreverses = YES; // This causes the animation to run forwards then backwards, thus doubling the duration, that's why a 3-second period is using 1.5 as duration
animation.removedOnCompletion = NO;
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
animation.beginTime = time;
// animation.beginTime = AVCoreAnimationBeginTimeAtZero;
ann.startLayer.hidden = NO;
ann.startLayer.opacity = 0.0;
ann.startLayer.masksToBounds = YES;
[ann.startLayer addAnimation:animation forKey:@"animateOpacity"];
[animationLayer addSublayer:ann.startLayer];
ann.typeLayer.hidden = NO;
ann.typeLayer.opacity = 0.0;
ann.typeLayer.masksToBounds = YES;
[ann.typeLayer addAnimation:animation forKey:@"animateOpacity"];
[animationLayer addSublayer:ann.typeLayer];
ann.detailLayer.hidden = NO;
ann.detailLayer.opacity = 0.0;
ann.detailLayer.masksToBounds = YES;
[ann.detailLayer addAnimation:animation forKey:@"animateOpacity"];
[animationLayer addSublayer:ann.detailLayer];
}