只使用 CLImageEditor 中的一个工具
Using only one tool from CLImageEditor
我正在努力在图片上添加文字。我发现 CLImageEditor 工具非常好。但我只想在我自己的主题中使用添加文本工具。那么我可以在我的应用程序中使用该工具吗?或我可以在我的应用程序中使用的任何其他工具。
您可以为每个工具执行此操作。
CLImageToolInfo *tool = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];
tool.available = NO; // if available is set to NO, it is removed from the menu view.
不,您不能直接打开子菜单。可以在 https://github.com/yackle/CLImageEditor/issues
向他们提出问题
如果您只想显示几个选项或想自定义项目位置,您可以这样做:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CLImageEditor *editor = [[CLImageEditor alloc] initWithImage:image];
editor.delegate = self;
CLImageToolInfo *tool1 = [editor.toolInfo subToolInfoWithToolName:@"CLAdjustmentTool" recursive:NO];
CLImageToolInfo *tool2 = [editor.toolInfo subToolInfoWithToolName:@"CLBlurTool" recursive:NO];
CLImageToolInfo *tool3 = [editor.toolInfo subToolInfoWithToolName:@"CLRotateTool" recursive:NO];
CLImageToolInfo *tool4 = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];
tool1.available = NO;
tool2.available = NO;
tool3.available = NO;
tool4.available = NO;
[picker pushViewController:editor animated:YES];
}
这可以通过如下调整现有代码来实现:
//First disable all the tools like below but the one you need.
var tool = editor.toolInfo.subToolInfoWithToolName("CLRotateTool", recursive: false)
tool.available = false
//replace below 4 functions in CLImageEditorView Controller
- (void)setMenuView
{
CGFloat x = 0;
CGFloat W = 70;
CGFloat H = _menuView.height;
int toolCount = 0;
CGFloat padding = 0;
for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
if(info.available){
toolCount++;
}
}
CGFloat diff = _menuView.frame.size.width - toolCount * W;
if (0<diff && diff<2*W) {
padding = diff/(toolCount+1);
}
for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
if(!info.available){
continue;
}
CLToolbarMenuItem *view = [CLImageEditorTheme menuItemWithFrame:CGRectMake(x+padding, 0, W, H) target:self action:@selector(tappedMenuView:) toolInfo:info];
[_menuView addSubview:view];
x += W+padding;
[self tappedMenuView:view];
}
_menuView.contentSize = CGSizeMake(MAX(x, _menuView.frame.size.width+1), 0);
}
- (IBAction)pushedCancelBtn:(id)sender
{
_imageView.image = _originalImage;
[self resetImageViewFrame];
self.currentTool = nil;
[self pushedCloseBtn:nil];
}
- (IBAction)pushedDoneBtn:(id)sender
{
self.view.userInteractionEnabled = NO;
[self.currentTool executeWithCompletionBlock:^(UIImage *image, NSError *error, NSDictionary *userInfo) {
if(error){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
else if(image){
_originalImage = image;
_imageView.image = image;
[self resetImageViewFrame];
self.currentTool = nil;
}
self.view.userInteractionEnabled = YES;
[self pushedFinishBtn:nil];
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = self.toolInfo.title;
self.view.clipsToBounds = YES;
self.view.backgroundColor = self.theme.backgroundColor;
self.navigationController.view.backgroundColor = self.view.backgroundColor;
if([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]){
self.automaticallyAdjustsScrollViewInsets = NO;
}
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
[self initNavigationBar];
[self initMenuScrollView];
[self initImageScrollView];
if(_imageView==nil){
_imageView = [UIImageView new];
[_scrollView addSubview:_imageView];
[self refreshImageView];
}
[self setMenuView];
}
您无法直接打开子菜单。
我创建了一个移除子工具的移除函数。 Swift 4.2
private func removeTools(tools: [String]) {
tools.forEach {
guard let imageEditor = self.imageEditor else { return }
let tool = imageEditor.toolInfo.subToolInfo(withToolName: [=10=], recursive: false)
tool?.available = false
}
}
你可以这样调用;
removeTools(tools: ["CLFilterTool", "CLEffectTool"])
我正在努力在图片上添加文字。我发现 CLImageEditor 工具非常好。但我只想在我自己的主题中使用添加文本工具。那么我可以在我的应用程序中使用该工具吗?或我可以在我的应用程序中使用的任何其他工具。
您可以为每个工具执行此操作。
CLImageToolInfo *tool = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];
tool.available = NO; // if available is set to NO, it is removed from the menu view.
不,您不能直接打开子菜单。可以在 https://github.com/yackle/CLImageEditor/issues
向他们提出问题如果您只想显示几个选项或想自定义项目位置,您可以这样做:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CLImageEditor *editor = [[CLImageEditor alloc] initWithImage:image];
editor.delegate = self;
CLImageToolInfo *tool1 = [editor.toolInfo subToolInfoWithToolName:@"CLAdjustmentTool" recursive:NO];
CLImageToolInfo *tool2 = [editor.toolInfo subToolInfoWithToolName:@"CLBlurTool" recursive:NO];
CLImageToolInfo *tool3 = [editor.toolInfo subToolInfoWithToolName:@"CLRotateTool" recursive:NO];
CLImageToolInfo *tool4 = [editor.toolInfo subToolInfoWithToolName:@"CLToneCurveTool" recursive:NO];
tool1.available = NO;
tool2.available = NO;
tool3.available = NO;
tool4.available = NO;
[picker pushViewController:editor animated:YES];
}
这可以通过如下调整现有代码来实现:
//First disable all the tools like below but the one you need.
var tool = editor.toolInfo.subToolInfoWithToolName("CLRotateTool", recursive: false)
tool.available = false
//replace below 4 functions in CLImageEditorView Controller
- (void)setMenuView
{
CGFloat x = 0;
CGFloat W = 70;
CGFloat H = _menuView.height;
int toolCount = 0;
CGFloat padding = 0;
for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
if(info.available){
toolCount++;
}
}
CGFloat diff = _menuView.frame.size.width - toolCount * W;
if (0<diff && diff<2*W) {
padding = diff/(toolCount+1);
}
for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
if(!info.available){
continue;
}
CLToolbarMenuItem *view = [CLImageEditorTheme menuItemWithFrame:CGRectMake(x+padding, 0, W, H) target:self action:@selector(tappedMenuView:) toolInfo:info];
[_menuView addSubview:view];
x += W+padding;
[self tappedMenuView:view];
}
_menuView.contentSize = CGSizeMake(MAX(x, _menuView.frame.size.width+1), 0);
}
- (IBAction)pushedCancelBtn:(id)sender
{
_imageView.image = _originalImage;
[self resetImageViewFrame];
self.currentTool = nil;
[self pushedCloseBtn:nil];
}
- (IBAction)pushedDoneBtn:(id)sender
{
self.view.userInteractionEnabled = NO;
[self.currentTool executeWithCompletionBlock:^(UIImage *image, NSError *error, NSDictionary *userInfo) {
if(error){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
else if(image){
_originalImage = image;
_imageView.image = image;
[self resetImageViewFrame];
self.currentTool = nil;
}
self.view.userInteractionEnabled = YES;
[self pushedFinishBtn:nil];
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = self.toolInfo.title;
self.view.clipsToBounds = YES;
self.view.backgroundColor = self.theme.backgroundColor;
self.navigationController.view.backgroundColor = self.view.backgroundColor;
if([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]){
self.automaticallyAdjustsScrollViewInsets = NO;
}
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
[self initNavigationBar];
[self initMenuScrollView];
[self initImageScrollView];
if(_imageView==nil){
_imageView = [UIImageView new];
[_scrollView addSubview:_imageView];
[self refreshImageView];
}
[self setMenuView];
}
您无法直接打开子菜单。
我创建了一个移除子工具的移除函数。 Swift 4.2
private func removeTools(tools: [String]) {
tools.forEach {
guard let imageEditor = self.imageEditor else { return }
let tool = imageEditor.toolInfo.subToolInfo(withToolName: [=10=], recursive: false)
tool?.available = false
}
}
你可以这样调用;
removeTools(tools: ["CLFilterTool", "CLEffectTool"])