一、相关接口类
| 接口类名 | 描述 |
| TAVEditor | SDK 操作入口类。 |
| TAVEffectInfo | 动效信息模型(只读查询结果)。 |
二、接口方法汇总
| 方法 | 参数 | 返回值 | 说明 |
| addMotionEffect:timeRange: | path:动效素材路径。timeRange:动效展示区间。 | int | 添加动效并返回 ID。 |
| updateMotionEffect:playRange: | effectId:动效 ID。timeRange:动效展示区间。 | void | 更新动效播放时间。 |
| setMotionEffect:trackIndex: | effectId:动效 ID。trackIndex:轨道下标。 | void | 保存轨道下标(业务使用)。 |
| removeMotionEffect: | effectId:动效 ID。 | void | 删除动效。 |
| removeAllMotionEffect | – | void | 删除所有动效。 |
| getEffectInfos | – | NSArray<TAVEffectInfo *> * | 获取当前所有已设置的动效。 |
三、添加动效
/// 设置特效/// – Parameters:/// – path: 特效素材路径/// – timeRange: 特效对应的时间区域/// – return: 特效id- (int)addMotionEffect:(NSString *)path timeRange:(CMTimeRange)timeRange;
四、调整动效播放时间
/// 更新特效播放时间/// – Parameters:/// – effectId: 创建特效时生成的id/// – timeRange: 特效展示区间- (void)updateMotionEffect:(int)effectId playRange:(CMTimeRange)timeRange;
五、删除动效
/// 删除特效/// – Parameter effectId: 创建特效时生成的id- (void)removeMotionEffect:(int)effectId;/// 删除所有特效- (void)removeAllMotionEffect;
六、TAVEffectInfo 字段
| 字段 | 类型 | 说明 |
| effectId | int | 动效 ID。 |
| effectPath | NSString * | 动效路径。 |
| timeRange | CMTimeRange | 动效在时间轴的播放区间。 |
| extraInfo | NSDictionary * | 扩展字段。 |
| trackIndex | NSInteger | 轨道下标(可用于业务)。 |
七、使用示例
// 添加动效(生效区间 0 ~ 2s)CMTimeRange range = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(2, 600));int effectId = [editor addMotionEffect:@"/path/to/motion" timeRange:range];// 调整动效播放时间(改为 3s ~ 5s)[editor updateMotionEffect:effectId playRange:CMTimeRangeMake(CMTimeMakeWithSeconds(3, 600), CMTimeMakeWithSeconds(2, 600))];// 查询当前所有动效NSArray<TAVEffectInfo *> *effects = [editor getEffectInfos];// 删除动效[editor removeMotionEffect:effectId];// 删除所有动效[editor removeAllMotionEffect];
注意:说明:
注意:添加/删除动效后需调用 flushImmediately 刷新预览才能看到效果。