-
Notifications
You must be signed in to change notification settings - Fork 103
/
WBGMosicaViewController.m
102 lines (86 loc) · 3.22 KB
/
WBGMosicaViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// WBGMosicaViewController.m
// FBSnapshotTestCase
//
// Created by 石磊 on 2018/3/30.
//
#import "WBGMosicaViewController.h"
#import "XScratchView.h"
#import "XRGBTool.h"
@interface WBGMosicaViewController ()
@property (nonatomic, strong) XScratchView *scratchView;
@property (nonatomic, strong) UIView *toolView;
@end
@implementation WBGMosicaViewController
- (instancetype)initWithImage:(UIImage *)image frame:(CGRect )frame {
self = [super init];
if (self) {
self.image = image;
self.frame = frame;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
CGFloat WIDTH = self.view.frame.size.width;
CGFloat HEIGHT = self.view.frame.size.height;
XScratchView *scratchView = [[XScratchView alloc] initWithFrame:self.frame];
// scratchView.mosaicImage = [XRGBTool getFilterMosaicImageWith:[UIImage imageNamed:@"qq.png"]];
scratchView.surfaceImage = self.image;
scratchView.mosaicImage = [XRGBTool getMosaicImageWith:self.image level:0];
_scratchView = scratchView;
[self.view addSubview:scratchView];
UIView *toolView = [[UIView alloc] init];
toolView.frame = CGRectMake(0, HEIGHT - 49, WIDTH, 49);
toolView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
[self.view addSubview:toolView];
_toolView = toolView;
CGFloat btnW = WIDTH / 3.0;
NSArray *arr = @[@"返回",@"撤销",@"完成"];
for (int i = 0; i < arr.count; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(btnW * i, 0, btnW, 49);
btn.tag = 100 + i;
btn.titleLabel.font = [UIFont systemFontOfSize:12];
btn.accessibilityLabel = arr[i];
[btn setTitle:arr[i] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[toolView addSubview:btn];
}
}
- (void)buttonAction:(UIButton *)btn {
switch (btn.tag) {
case 100:
[self dismissViewControllerAnimated:YES completion:nil];
break;
case 101:
[_scratchView recover];
break;
case 102:
{
__weak typeof(self) weakSelf = self;
UIGraphicsBeginImageContextWithOptions(weakSelf.scratchView.frame.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[weakSelf.scratchView.layer renderInContext:context];
UIImage *deadledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if (weakSelf.mosicaCallback) {
weakSelf.mosicaCallback(deadledImage);
}
[weakSelf dismissViewControllerAnimated:YES completion:nil];
}
break;
default:
break;
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end