工作中遇到了和微信编辑类似的需求,网上并没有找到相应的代码,所以只能自己动手丰衣足食了
先直接放代码
仿微信剪裁代码git地址
功能介绍
-
涂鸦
-
添加文字
-
剪裁
-
马赛克
代码使用
将CXImageEditTool
拖入项目中
示例ViewController代码
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
ViewController.m
#import "ViewController.h"
#import "Masonry.h"
#import "CXImageEditView.h"
@interface ViewController ()
@property(nonatomic, strong) UIImageView *editIgv;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
_editIgv = [UIImageView new];
_editIgv.image = [UIImage imageNamed:@"zuo.jpg"];
_editIgv.contentMode = UIViewContentModeScaleAspectFit;
_editIgv.userInteractionEnabled = YES;
[self.view addSubview:_editIgv];
[_editIgv mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.mas_equalTo(0);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImage)];
[_editIgv addGestureRecognizer:tap];
}
//进入图片编辑功能
- (void)tapImage {
CXImageEditView *editVi = [[CXImageEditView alloc]initWithEditImage:[UIImage imageNamed:@"zuo.jpg"]];
__weak typeof(self) weakSelf = self;
__weak typeof(editVi) weakEditVi = editVi;
editVi.completeEdit = ^(UIImage * _Nonnull resultImg) {
weakSelf.editIgv.image = resultImg;
[weakEditVi removeFromSuperview];
};
[self.view addSubview:editVi];
[editVi mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.mas_equalTo(0);
}];
}
@end