【问题标题】:CAKeyframeAnimation not visible on videoCAKeyframeAnimation 在视频中不可见
【发布时间】:2014-06-06 12:45:49
【问题描述】:

我正在制作一个应用来处理视频,现在我在视频上方添加精灵动画。

为此,我使用 CAKeyframeAnimation,我在管理器中有一个方法,用于添加动画精灵。

 // add effect on the video
[EffectManager addEffectOnVideoAtURL:outputURL handler:^{
  NSLog(@"video exported with aimations");
}];

问题是当这个 videoURL 存储在我的应用程序的文件夹中时,CAKeyframeAnimation 是不可见的。

但是当我第一次将视频导出到库/相机胶卷,然后加载并在这个导出的视频上添加效果时,它们是可见的。

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
 // export the video to the library/camera roll
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]) {
    [library writeVideoAtPathToSavedPhotosAlbum:outputURL completionBlock:^(NSURL *assetURL, NSError *error){
        dispatch_async(dispatch_get_main_queue(), ^{
              // add effect on the video
              [EffectManager addEffectOnVideoAtURL:assetURL handler:^{
                 NSLog(@"video exported with aimations");
                }];
        });
    }];
}

这段代码,使用库可以正常工作,但我不想将中间视频保存到库中。

我尝试过以异步方式使用代码的第一个sn-p,但结果是一样的。

我也尝试从库中加载电影,并使用第一个 sn-p 代码,但结果相同,没有 CAKeyframeAnimation。

知道为什么 CAKeyframeAnimation 仅在视频首次导出到图书馆/照片卷时才可见吗?

【问题讨论】:

    标签: ios xcode video calayer cakeyframeanimation


    【解决方案1】:

    终于和PhotoScroll无关了

    CAKeyFrameAnimation.removedOnCompletion 默认设置为 YES。 当它被添加到 CALayer 时,它会混淆视频导出。

    因此,通过将其设置为 NO,CAKeyFrameAnimation 在动画中可见。

    NSMutableArray* animationArray = [NSMutableArray array];
    UIImage*img1 = [UIImage imageWithContentsOfFile:path];
    [animationArray addObject:(__bridge id)[img1 CGImage]];
    UIImage*img2 = [UIImage imageWithContentsOfFile:path];
    [animationArray addObject:(__bridge id)[img2 CGImage]];
    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
    [animation setCalculationMode:kCAAnimationDiscrete];
    [animation setDuration:0.5f];
    [animation setRepeatCount:HUGE_VALF];
    [animation setValues:[[NSArray alloc] initWithArray:animationArray]];
    // this line does the fix:
    animation.removedOnCompletion = NO;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-05
      • 1970-01-01
      • 2012-09-28
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      相关资源
      最近更新 更多