更新时间 : 2021-02-22 09:30:40
贴纸的管理使用 SXStickerManager ,在 SXTemplate 中获取。
可以添加多个贴纸,移除贴纸需要使用添加贴纸时获取到的 ID。
//添加贴纸
_stickerId = [_mTemplate.stickerManager addSticker:stickerPath];
//移除贴纸
[_mTemplate.stickerManager removeSticker:_stickerId];
每个贴纸可以进行旋转位移缩放,来达到期望的效果。
//设置缩放
[_mTemplate.stickerManager setStickerScale:_stickerId scaleX:scale.x * pinch.scale scaleY:scale.y * pinch.scale];
//设置位移
[_mTemplate.stickerManager setStickerPosition:_stickerId position:CGPointMake(_selectModelLabel.center.x / _playerScale, _selectModelLabel.center.y / _playerScale)];
//设置旋转
float rot = [_mTemplate.stickerManager getStickerRotation:_stickerId];
rot += rotation.rotation / M_PI * 180;
[_mTemplate.stickerManager setStickerRotate:_stickerId rotation:rot];
每个贴纸文件的解析可以参考标准模板,替换素材的 index 是这个素材在可替换素材中的排序。
//替换贴纸中的index为0的可替换素材, path为替换上去的素材路径
[_mTemplate.stickerManager replaceSource:_stickerId sourceIndex:0 withSource:path];
也可以针对指定素材设置旋转位移缩放。
//设置缩放
CGPoint scale = [_mTemplate.stickerManager getSourceScale:_stickerId sourceIndex:0];
[_mTemplate.stickerManager setSourceScale:_stickerId sourceIndex:0 scaleX:scale.x * pinch.scale scaleY:scale.y * pinch.scale];
//设置位移
CGPoint translation = [pan translationInView:_modelView];
CGPoint position = [_mTemplate.stickerManager getSourcePositon:_stickerId sourceIndex:0];
[_mTemplate.stickerManager setSourcePosition:_stickerId sourceIndex:0 position:CGPointMake(position.x + translation.x / _playerScale, position.y + translation.y / _playerScale)];
//设置旋转
float rot = [_mTemplate.stickerManager getSourceRotation:_stickerId sourceIndex:0];
rot += rotation.rotation / M_PI * 180;
[_mTemplate.stickerManager setSourceRotate:_stickerId sourceIndex:0 rotation:rot];
贴纸的管理使用 SXStickerManager ,在 SXTemplate 中获取。
可以添加多个贴纸,移除贴纸需要使用添加贴纸时获取到的 ID。
//添加贴纸
_stickerId = [_mTemplate.stickerManager addSticker:stickerPath];
//移除贴纸
[_mTemplate.stickerManager removeSticker:_stickerId];
每个贴纸可以进行旋转位移缩放,来达到期望的效果。
//设置缩放
[_mTemplate.stickerManager setStickerScale:_stickerId scaleX:scale.x * pinch.scale scaleY:scale.y * pinch.scale];
//设置位移
[_mTemplate.stickerManager setStickerPosition:_stickerId position:CGPointMake(_selectModelLabel.center.x / _playerScale, _selectModelLabel.center.y / _playerScale)];
//设置旋转
float rot = [_mTemplate.stickerManager getStickerRotation:_stickerId];
rot += rotation.rotation / M_PI * 180;
[_mTemplate.stickerManager setStickerRotate:_stickerId rotation:rot];
每个贴纸文件的解析可以参考标准模板,替换素材的 index 是这个素材在可替换素材中的排序。
//替换贴纸中的index为0的可替换素材, path为替换上去的素材路径
[_mTemplate.stickerManager replaceSource:_stickerId sourceIndex:0 withSource:path];
也可以针对指定素材设置旋转位移缩放。
//设置缩放
CGPoint scale = [_mTemplate.stickerManager getSourceScale:_stickerId sourceIndex:0];
[_mTemplate.stickerManager setSourceScale:_stickerId sourceIndex:0 scaleX:scale.x * pinch.scale scaleY:scale.y * pinch.scale];
//设置位移
CGPoint translation = [pan translationInView:_modelView];
CGPoint position = [_mTemplate.stickerManager getSourcePositon:_stickerId sourceIndex:0];
[_mTemplate.stickerManager setSourcePosition:_stickerId sourceIndex:0 position:CGPointMake(position.x + translation.x / _playerScale, position.y + translation.y / _playerScale)];
//设置旋转
float rot = [_mTemplate.stickerManager getSourceRotation:_stickerId sourceIndex:0];
rot += rotation.rotation / M_PI * 180;
[_mTemplate.stickerManager setSourceRotate:_stickerId sourceIndex:0 rotation:rot];