接口类名 | 描述 |
TAVEditor | SDK 操作入口类。 |
ITAVStickerManager | 贴纸操作入口类。 |
TAVMediaStickerItem | 贴纸数据模型类。 |
TAVEditor 直接进行获取:// 获取TAVEditor apiNSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"LightCore" ofType:@"bundle"];self.tavEditor = [[TAVEditor alloc] initWithRenderSize:CGSizeZero assetsPath:bundlePath];// 获取贴纸操作接口id<ITAVStickerManager> stickerManager = [self.tavEditor getStickerManager];
TAVMediaStickerItem 中,所以在操作贴纸之前,必须先要有 TAVMediaStickerItem 对象,setTimeRange,不设置默认为整个资源时长。// 1、创建一个文本贴纸NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"text_default" ofType:@"bundle"];TAVMediaStickerItem *stickerItem = [stickerManager createStickerItem:textPath stickerType:TAVStickerTypeText];// 设置文本贴纸字体// 获取字体font,fontPath为字体路径,fontFamily和fontStyle不知道可填空字符串PAGFont *pagFont = [PAGFont RegisterFont:fontPathfamily:fontFamilystyle:fontStyle];stickerItem.font = pagfont;stickerItem.timeRange = timerange;// 2、创建一个图片贴纸NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"image_default" ofType:@"bundle"];TAVMediaStickerItem *stickerItem = [stickerManager createStickerItem:stickerPath stickerType:TAVStickerTypeImage];// 设置图片NSString *imagePath = ....;stickerItem.imageFilePath = imagePath;// 3、创建一个动态类贴纸// 这是指向main.pag的一个路径。sticker__plfttz_01.bundle这个下面有main.pag文件NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"sticker__plfttz_01" ofType:@"bundle"];TAVMediaStickerItem *stickerItem = [[TAVMediaStickerItem alloc] initWithStickerID:@"stickerPlfttz01Id" resourceInfoPath:stickerPath];
[stickerManager loadStickerItem:stickerItem];
@protocol ITAVStickerViewDataSource <NSObject>/// 根据贴纸对象返回贴纸视图,可继承自TAVStickerView自定义某些控件/// - Parameter stickerItem: 贴纸对象- (TAVStickerView *)stickerViewWithStickerItem:(TAVMediaStickerItem *)stickerItem;@end- (void)setStickerViewDataSource:(id<ITAVStickerViewDataSource>)dataSource;
@interface MyStickerContentView : TAVStickerView/// ...自行实现业务逻辑@end#pragma mark - ITAVStickerViewDataSource- (TAVStickerView *)stickerViewWithStickerItem:(TAVMediaStickerItem *)stickerItem{// 自定义的贴纸View需要继承自TAVStickerViewMyStickerContentView *stickerView = [[TAVMagicStickerView alloc] initWithStickerItem:stickerItem];return stickerView;}
@interface MyStickerContentView : TAVStickerContentView/// ...自行实现业务逻辑@end
TAVStickerManager 中的 setStickerContentView 接口设置自定义的贴纸容器布局。/// 绑定添加贴纸的容器视图/// - Parameter stickerContentView: 需要继承自TAVStickerContentView- (void)setStickerContentView:(TAVStickerContentView *)stickerContentView;
// 设置文字stickerItem.text = @"";// 设置字体PAGFont *pagFont = [PAGFont RegisterFont:fontPathfamily:fontFamilystyle:fontStyle];stickerItem.font = pagfont;
@property (nonatomic, copy) NSString *text; //文本贴纸的文本@property (nonatomic, strong, readonly) NSString *defaultText; //文本贴纸的默认文本@property (nonatomic, strong) UIColor *textColor; //文本贴纸的文字颜色@property (nonatomic, strong) UIColor *bgColor; //整个贴纸背景色@property (nonatomic, strong) PAGFont *pagFont; //文字字体/// 描边@property (nonatomic, assign) BOOL applyTextStroke; //开启文字描边@property (nonatomic, assign) CGFloat textStrokeWidth; //文字描边厚度@property (nonatomic, strong) UIColor *textStrokeColor; //文字描边颜色/// 文字背景@property (nonatomic, strong) UIColor *textBgColor; //文字背景颜色@property (nonatomic, assign) CGFloat textBgAlpha; //文字背景透明度,取值范围 0 - 1
// 2、创建一个图片贴纸NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"image_default" ofType:@"bundle"];TAVMediaStickerItem *stickerItem = [[TAVMediaStickerItem alloc] initWithStickerID:@"imageDefaultId" resourceInfoPath:stickerPath];// 切换图片TAVStickerImageItem *imageItem = stickerItem.sticker.imageList.firstObject;NSString *imagePath = ....;imageItem.filePath = imagePath;
文档反馈