本文主要介绍短视频编辑 UIKit SDK 的 iOS 端 API 接口文档,以便于查阅和使用。
TAVMagicUIKitBase
统一对外配置入口(
TAVMagicUIKit/TAVMagicUIKitBase.h),纯类方法接口,一次配置全局生效。接口方法汇总
API | 描述 |
UIKit 全局初始化,内部自动调用 [TAVMagicBase initSDK:]。 | |
设置资源提供者。 | |
设置编辑拦截器。 | |
+ setRecorderInterceptor: | 设置录制拦截器。 |
设置自定义多语言 JSON。 | |
设置首选语言代码。 | |
设置全局 UI 事件监听(埋点上报)。 | |
设置编辑最小时长,默认 6s。 | |
设置编辑最大时长,默认 60*60s。 | |
创建预览编辑页(资源数组)。 | |
创建预览编辑页(草稿)。 | |
创建预览编辑页(已有 editor)。 | |
创建草稿箱页。 | |
创建录制页。 |
initUIKit:
描述
UIKit 全局初始化,内部自动调用
[TAVMagicBase initSDK:]。接口
+ (BOOL)initUIKit:(nullable NSString *)assetPath参数
参数名 | 类型 | 说明 |
assetPath | NSString * | LightCore.bundle 模型资源路径,传 nil 默认从 mainBundle 获取。 |
返回值
类型:
BOOL说明:初始化是否成功。
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"LightCore" ofType:@"bundle"];BOOL ret = [TAVMagicUIKitBase initUIKit:bundlePath];
setMaterialProvider:
描述
设置资源提供者,KIT 内点击增加视频/图片/BGM 时会调用该协议内的方法。
接口
+ (void)setMaterialProvider:(nullable id<ITAVMaterialProvider>)materialProvider参数
参数名 | 类型 | 说明 |
materialProvider | id<ITAVMaterialProvider> | 资源提供者,传 nil 恢复默认实现。 |
返回值
类型:
voidsetEditInterceptor:
描述
设置编辑拦截器,回调某些操作是否可继续的事件拦截。
接口
+ (void)setEditInterceptor:(nullable id<ITAVEditInterceptor>)editInterceptor参数
参数名 | 类型 | 说明 |
editInterceptor | id<ITAVEditInterceptor> | 编辑拦截器,传 nil 恢复默认实现。 |
返回值
类型:
voidsetEventListener:
描述
设置全局 UI 事件监听器,所有面板操作/按钮点击都会通过此 block 回调。
接口
+ (void)setEventListener:(nullable TAVUIKitEventListener)listener参数
参数名 | 类型 | 说明 |
listener | TAVUIKitEventListener | 事件回调,传 nil 清除监听。 |
返回值
类型:
voidtypedef void(^TAVUIKitEventListener)(TAVUIKitEvent *event);@interface TAVUIKitEvent : NSObject@property (nonatomic, copy, readonly) NSString *name;@property (nonatomic, assign, readonly) NSTimeInterval timestamp;@property (nonatomic, strong, readonly, nullable) NSDictionary<NSString *, id> *params;@end
setMinimumEditableDuration: / setMaximumEditableDuration:
描述
设置可编辑时长下限/上限。
接口
+ (void)setMinimumEditableDuration:(NSTimeInterval)duration; // 默认 6.0s+ (void)setMaximumEditableDuration:(NSTimeInterval)duration; // 默认 60*60s
参数
参数名 | 类型 | 说明 |
duration | NSTimeInterval | 时长,单位秒。 |
返回值
类型:
voidcreatePreviewControllerWithResources:
描述
使用素材路径数组创建预览编辑页。
接口
+ (nullable TAVEditorPreviewController *)createPreviewControllerWithResources:(NSArray<TAVAlbumResource *> *)resources参数
参数名 | 类型 | 说明 |
resources | NSArray<TAVAlbumResource *> * | 输入资源数组。 |
返回值
类型:
TAVEditorPreviewController *说明:返回
nil 表示 UIKit 无权限。需先调用 [TAVMagicUIKitBase initUIKit:]。createPreviewControllerWithDraft: / createPreviewControllerWithEditor:
描述
分别使用草稿对象、已有的
TAVEditor 实例创建预览编辑页。接口
+ (nullable TAVEditorPreviewController *)createPreviewControllerWithDraft:(TAVDraft *)draft;+ (nullable TAVEditorPreviewController *)createPreviewControllerWithEditor:(TAVEditor *)editor;
参数
参数名 | 类型 | 说明 |
draft | TAVDraft * | 草稿对象。 |
editor | TAVEditor * | 已有 editor 实例。 |
返回值
类型:
TAVEditorPreviewController *说明:返回
nil 表示 UIKit 无权限。createDraftViewController
描述
创建草稿箱页。
接口
+ (TAVDraftViewController *)createDraftViewController返回值
类型:
TAVDraftViewController *createRecorderController
描述
接口
+ (TAVRecorderController *)createRecorderController返回值
类型:
TAVRecorderController *setLocalizationJSON: / setPreferredLanguage:
描述
自定义多语言。传
nil 清除自定义翻译,恢复使用 bundle 内置翻译。接口
+ (void)setLocalizationJSON:(nullable NSDictionary<NSString *, NSDictionary<NSString *, NSString *> *> *)localizationJSON;+ (void)setPreferredLanguage:(nullable NSString *)preferredLanguage;
参数
参数名 | 类型 | 说明 |
localizationJSON | NSDictionary * | 格式 @{ @"en": @{ @"key": @"value" }, @"zh-Hans": @{ ... } }。 |
preferredLanguage | NSString * | 首选语言代码(如 @"en"、@"zh-Hans"),传 nil 使用系统语言。 |
返回值
类型:
voidTAVEditorPreviewController
短视频编辑的预览/剪辑页容器(
TAVMagicUIKit/TAVEditorPreviewController.h),继承 UIViewController。对外属性
属性 | 类型 | 说明 |
menuView | TAVEditorPreviewMenuView *(只读) | 界面右侧一竖排按钮父视图。 |
bgmView | TAVBgmView *(只读) | 背景音乐展示视图,默认隐藏。 |
backButton | UIButton *(weak, 只读) | 左上角返回按钮。 |
nextButton | UIButton *(weak, 只读) | next 按钮。 |
saveDraftButton | UIButton *(weak, 只读) | 底部「保存草稿」按钮。 |
exportButton | UIButton *(weak, 只读) | 底部「导出」按钮,点击回调与 nextButton 一致。 |
bottomButtonsHidden | BOOL | 默认 YES:只显示 nextButton;设为 NO 则隐藏 nextButton,显示「保存草稿 + 导出」。 |
nextClickCallback | block | next 按钮点击事件。 |
shouldHideMenuView | block | menuView 隐藏回调。 |
shouldShowMenuView | block | menuView 显示回调。 |
editor | TAVEditor *(weak, 只读) | 编辑 SDK 实例。 |
editorResource | id<ITAVEditorResource> | 编辑器资源提供者,需在 push 前设置。 |
初始化接口
API | 说明 |
使用素材数组初始化。 | |
使用草稿初始化。 | |
使用已有 editor 实例初始化。 |
说明:
三个方法均需先调用
[TAVMagicUIKitBase initUIKit:];返回 nil 表示 UIKit 无权限。initWithResources:
描述
使用素材资源数组初始化预览编辑页。
接口
- (instancetype)initWithResources:(NSArray<TAVAlbumResource *> *)resources参数
参数名 | 类型 | 说明 |
resources | NSArray<TAVAlbumResource *> * | 输入资源数组。 |
返回值
类型:
instancetype说明:需先调用
[TAVMagicUIKitBase initUIKit:];返回 nil 表示 UIKit 无权限。initWithDraft:
描述
使用已有草稿对象初始化预览编辑页。
接口
- (instancetype)initWithDraft:(TAVDraft *)draft参数
参数名 | 类型 | 说明 |
draft | TAVDraft * | 草稿对象。 |
返回值
类型:
instancetype说明:需先调用
[TAVMagicUIKitBase initUIKit:];返回 nil 表示 UIKit 无权限。initWithTavEditor:
描述
使用已有的
TAVEditor 实例初始化预览编辑页。接口
- (instancetype)initWithTavEditor:(TAVEditor *)editor参数
参数名 | 类型 | 说明 |
editor | TAVEditor * | 已有 editor 实例。 |
返回值
类型:
instancetype说明:返回
nil 表示 UIKit 无权限。页面控制接口
API | 说明 |
跳转编辑页。 | |
跳转编辑页并选中第一条 BGM 轨道。 | |
调起 BGM 选择面板。 | |
调起文字贴纸面板,添加文字贴纸。 | |
调起音量设置面板。 | |
跳转录音面板,添加录音。 | |
业务记录的录音 id(NSNumber 数组),用于区分 bgm 与录音。 |
pushEditController
描述
跳转编辑页。
接口
- (void)pushEditController返回值
类型:
voidpushEditAndSelectBgmTrack
描述
跳转编辑页并选中第一条 BGM 轨道。
接口
- (void)pushEditAndSelectBgmTrack返回值
类型:
voidshowBgmSelectionPanel
描述
调起 BGM 选择面板,选择 BGM。
接口
- (void)showBgmSelectionPanel返回值
类型:
voidshowTextInputPanel
描述
调起文字贴纸面板,添加文字贴纸。
接口
- (void)showTextInputPanel返回值
类型:
voidshowVolumePanel
描述
调起音量设置面板,设置音量。
接口
- (void)showVolumePanel返回值
类型:
voidgotoVoiceoverPanel
描述
跳转录音面板,添加录音。
接口
- (void)gotoVoiceoverPanel返回值
类型:
voidvoiceoverIds
描述
业务记录的录音 id,用于区分 BGM 与录音。
接口
- (NSArray *)voiceoverIds返回值
类型:
NSArray *说明:录音 id 列表(
NSNumber 数组)。生命周期
SDK 未提供
onResume / onPause / onDestroy / onBackPressed 这类生命周期方法,页面生命周期与返回由系统自行管理。对应机制:1. 标准
UIViewController 生命周期(viewDidLoad / viewWillAppear: / viewWillDisappear: / viewWillLayoutSubviews 等),由组件内部转发给各 Processor。2. 页面返回由
UINavigationController 统一管理。3. 容器级关闭走
ITAVContainer:closeContainer / closeContainerWithCompletion:。ITAVMaterialProvider
资源提供者协议(
TAVMagicUIKit/ITAVMaterialProvider.h),方法均为 @optional。typedef void(^handleBgmSelectResultFunc)(TAVBgmResource *bgmResouce);typedef void(^handleAlbumSelectResultFunc)(NSArray<TAVAlbumResource *> *resourceList);typedef void(^handleEffectDataResultFunc)(TAVRecorderEffectItem * _Nullable effectModel, BOOL isFinished);@protocol ITAVMaterialProvider <NSObject>@optional/// 拉取 BGM- (void)getBgmWithHandler:(handleBgmSelectResultFunc)handler;/// 拉取相册素材- (void)getAlbumFilesForType:(TAVAlbumOptions *)option withHandler:(handleAlbumSelectResultFunc)handler;/// 拉取特效数据;实现此方法后内部 effectPanel 不再弹出- (void)getEffectDataWithHandler:(handleEffectDataResultFunc)handler;@end
方法 | 说明 |
getBgmWithHandler: | KIT 内需要选择 BGM 时回调,业务方拉起自己的 BGM 选择界面后回传结果。 |
getAlbumFilesForType:withHandler: | 按 TAVAlbumOptions 配置拉取相册素材。 |
getEffectDataWithHandler: | 拉取特效数据;实现后 UIKit 内部特效面板不再弹出。 |
TAVAlbumOptions
字段 | 类型 | 说明 |
count | - | 需要选择的素材数量。 |
type | TAVResourceType | 资源类型。 |
from | TAVResourceFrom | 来源。 |
source | TAVAlbumRequestSource | 请求来源: EditMedia / DuetMedia / SelectOverlay / UploadClip / ReplaceClip。 |
autoDismiss | BOOL | 是否自动关闭选择页。 |
ITAVEditInterceptor
编辑拦截器协议(
TAVMagicUIKit/ITAVEditInterceptor.h),方法均为 @optional。方法 | 说明 |
- (BOOL)canAddNewTrack:(TAVTrackType)type count:(NSInteger)currentCount | 是否可以新增指定类型轨道(按当前数量判断)。 |
- (BOOL)canAddNewTrack:(TAVTrackType)type currentTime:(CMTime)currentTime duration:(CMTime)totalDuration | 是否可以新增指定类型轨道(按时间点与总时长判断)。 |
- (BOOL)canSplitTrack:(TAVTrackType)type currentTime:(CMTime)currentTime timeRange:(CMTimeRange)timeRange | 当前轨道位置是否可分割。 |
TAVTrackType:TAVTrackTypeText / TAVTrackTypeOverlay / TAVTrackTypeVideo / TAVTrackTypeBgm / TAVTrackTypeVoiceOver。ITAVEditorResource
编辑器面板资源配置协议(
TAVMagicUIKit/ITAVEditorResource.h),主线程回调。typedef void(^TAVPanelConfigCallback)(TAVPanelUIConfig * _Nullable config, NSError * _Nullable error);@protocol ITAVEditorResource <NSObject>- (void)getEffectPanelConfig:(TAVPanelConfigCallback)callback;- (void)getFilterPanelConfig:(TAVPanelConfigCallback)callback;- (void)getStickerPanelConfig:(TAVPanelConfigCallback)callback;@end
方法 | 说明 |
getEffectPanelConfig: | 特效面板配置。 |
getFilterPanelConfig: | 滤镜面板配置。 |
getStickerPanelConfig: | 贴纸面板配置。 |
默认实现
TAVDefaultEditorResource:- (instancetype)initWithEffectJSON:(nullable NSString *)effectJSONfilterJSON:(nullable NSString *)filterJSONstickerJSON:(nullable NSString *)stickerJSON;
TAVPanelUIConfig<ItemType>:title + items。TAVDraftViewController
草稿箱页(
TAVMagicUIKit/TAVDraftViewController.h)。@protocol TAVDraftViewControllerDelegate <NSObject>- (void)draftViewItemClick:(TAVDraft *)draft;@end@interface TAVDraftViewController : UIViewController@property (nonatomic, readonly) TAVEditor *editor;@property (nonatomic, weak) id<TAVDraftViewControllerDelegate> delegate;@end
TAVCoverSelectorController
封面选择器。
@protocol TAVCoverSelectorControllerDelegate <NSObject>- (void)onSelectedCoverImg:(UIImage *)img atPosition:(CMTime)position;@end@interface TAVCoverSelectorController : UIViewController@property (nonatomic, weak) id<TAVCoverSelectorControllerDelegate> delegate;@property (nonatomic, assign) CMTimeRange useTimeRange; // 实际用于抽帧的范围- (instancetype)initWithEditor:(TAVEditor *)editor;- (void)selectCoverImgAtPosition:(CMTime)position;@end
说明:
TAVEditorPreviewController 内部已实现 TAVCoverSelectorControllerDelegate,并维护 selectedCoverImage / selectedCoverPosition(保存草稿时写入 draft thumbnail,再次进入时回显)。TAVAlbumPickerController
UIKit 内置相册选择器(
TAVMagicUIKit/TAVAlbumPickerController.h),可独立于编辑流程使用。@protocol TAVAlbumPickerControllerDelegate <NSObject>@optional- (void)albumPickerController:(TAVAlbumPickerController *)pickerControllerdidFinishPickingAlbumAssets:(NSArray<TAVAlbumAssetProtocol> *)albumAssets;- (void)albumPickerControllerDidCancel:(TAVAlbumPickerController *)pickerController;- (void)albumPickerController:(TAVAlbumPickerController *)pickerControllershowAlertTips:(NSString *)alertTips;- (void)albumPickerController:(TAVAlbumPickerController *)pickerControllerdidFinishPickingSpecialAlbumAssets:(NSArray<TAVAlbumAssetProtocol> *)albumAssets;@end@interface TAVAlbumPickerController : UINavigationController@property (nonatomic, weak) id<TAVAlbumPickerControllerDelegate> pickerDelegate;- (instancetype)initWithOptions:(TAVAlbumPickerOptions *)options;- (instancetype)initWithOptions:(TAVAlbumPickerOptions *)options rootViewController:(UIViewController *)rootViewController;@end
TAVAlbumPickerFactory:+ (void)showAlbumPickInViewController:(UIViewController *)vccompletion:(void (^)(NSMutableArray<TAVAlbumResource *> *resources))completion;+ (TAVAlbumPickerOptions *)defaultAlbumPickerOptions;
TAVAlbumPickerOptions 常用字段:mediaType(TAVAlbumAssetType:Unknown / Image / Video / All)、minimumSelectionCount、maximumSelectionCount、pattern(Default / FastSingle / RepeatedSelection)、autoDismiss、customData、assetSelectorViewTips、customViewOptions(可替换相册 VC / Cell / 预览页 / 导航条等 Class)。TAVAuthorizer / TAVAlbumAuthorizer
系统权限检查工具。
/// 麦克风+ (void)checkMicrophoneAuthorize:(void(^)(AVAuthorizationStatus status))handler;+ (UIAlertController *)MicrophoneNotAuthorityAlertController;/// 相册+ (void)checkAlbumAuthorize:(void(^)(PHAuthorizationStatus status))handler;+ (UIAlertController *)albumNotAuthorityAlertController;
说明:
iOS 侧没有需要业务方实现的权限提供器协议,系统权限由宿主 App 在 Info.plist 声明并自行申请。
主题与资源定制
类 | 说明 |
TAVThemeConfig | brandColor、brandGradient(TAVGradientConfig)、primaryBgColor、mainMenuColor、timeLinePointerColor、各类 Track 颜色等。 |
TAVCustomUIManager | + shareInstance,themeConfig 属性。 |
TAVBdManager | - registerBundle: / - unregisterBundle: / + pathWithName:type:,用于替换图标(新建同名图片的 bundle 并注册)。 |
TAVLocalizationManager | localizationJSON / preferredLanguage / - localizedStringForKey:。 |
TAVMagicUIKitVersion | UIKit 版本号常量。 |
TAVThemeConfig *themeConfig = [TAVCustomUIManager shareInstance].themeConfig;themeConfig.brandColor = [UIColor tvc_colorWithHexString:@"#4BEF65"];themeConfig.brandGradient = [TAVGradientConfig configWithColors:@[color1, color2, color3]];[[TAVBdManager sharedInstance] registerBundle:@"customTheme"];