iOS 仿微信圖片編輯功能

工作中遇到了和微信編輯類似的需求,網(wǎng)上并沒有找到相應(yīng)的代碼,所以只能自己動手豐衣足食了
先直接放代碼
仿微信剪裁代碼git地址


功能介紹

  1. 涂鴉

    涂鴉.gif

  2. 添加文字

    添加文字.gif

  3. 剪裁

    剪裁.gif

  4. 馬賽克

    馬賽克.gif


代碼使用

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];
}

//進(jìn)入圖片編輯功能
- (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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容