AVAssetExportSession导出时,AVVideoCompositionCoreAnimationTool没有对自定义属性进行动画处理的问题。
创始人
2024-11-12 20:00:26
0

在设置AVVideoComposition时,需要为AVVideoCompositionCoreAnimationTool设置delegate,并实现其中的“animationTool:didAnimateProperty:ofLayer:atTime:withValue:”方法。在该方法内,判断自定义属性的键是否符合动画处理,如果是则对其进行相应的动画处理。

示例代码:

// 自定义属性的键
let customAnimationKey = "customAnimationKey"

// 设置AVAssetExportSession
let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality)
exporter.outputFileType = .mp4
exporter.videoComposition = videoComposition

// 设置AVVideoCompositionCoreAnimationTool
let animationTool = AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer, in: videoComposition)
animationTool.delegate = self // 设置delegate

videoComposition.animationTool = animationTool

// 实现AVVideoCompositionCoreAnimationToolDelegate中的方法,进行动画处理
extension ViewController: AVVideoCompositionCoreAnimationToolDelegate {
    func animationTool(_ animationTool: AVVideoCompositionCoreAnimationTool, didAnimateProperty prop: String, ofLayer layer: CALayer, atTime time: CMTime, withValue value: Any) {

        if prop == customAnimationKey {
            // 对自定义属性进行动画处理
            let anim = CABasicAnimation(keyPath: "opacity")
            anim.fromValue = 0
            anim.toValue = 1
            anim.duration = 1
            layer.opacity = 1
            layer.add(anim, forKey: "opacity")
        }
    }
}

相关内容

热门资讯

总算明白!hhpoker真的假... 总算明白!hhpoker真的假的,wepokerplus外挂,新2025版(有挂技巧);《WPK辅助...
热点讨论!hhpoker万能辅... 热点讨论!hhpoker万能辅助器,wejoker黑侠辅助器,2025新版技巧(有挂神器);大神普及...
免费测试版!hhpoker为什... 免费测试版!hhpoker为什么一直输,hhpoker透视方法,2025新版总结(有挂教程);大神普...
一分钟揭秘!wepoker有辅... 一分钟揭秘!wepoker有辅助插件吗,wepoker辅助器最新版本更新内容,微扑克教程(有挂神器)...
一分钟秒懂!wepoker透视... 一分钟秒懂!wepoker透视是真的吗,德普辅助器辅助器怎么用,黑科技教程(有挂软件);支持多人共享...
揭秘!pokemmo辅助工具,... 1、揭秘!pokemmo辅助工具,wepoker私局辅助,技巧教程(有挂软件);详细教程。2、pok...
大神推荐!wepoker怎么看... 大神推荐!wepoker怎么看底牌,pokemmo修改器手机版,科技教程(有挂软件);原来确实真的有...
我来向大家传授!约局吧开挂神器... 我来向大家传授!约局吧开挂神器是真的吗,wepoker好友助力码,攻略教程(有挂透视);实战中需综合...
查到实测!hhpoker一直输... 1、查到实测!hhpoker一直输有挂吗,约局吧德州真的存在透视吗,2025新版教程(有挂神器)2、...
一秒答解!wepoker辅助器... 一秒答解!wepoker辅助器如何使用,hhpoker有后台操控吗,教你教程(有挂辅助)是一款可以让...