-
Notifications
You must be signed in to change notification settings - Fork 1
/
ViewController.m
88 lines (69 loc) · 2.93 KB
/
ViewController.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
//
// ViewController.m
//
// Created by Tenfay on 2017/1/16.
// Copyright © 2017 Tenfay. All rights reserved.
//
#import "ViewController.h"
#import "DYFBlurEffect.h"
@interface ViewController ()
@property (weak , nonatomic) IBOutlet UIImageView *imgView;
@property (strong, nonatomic) DYFBlurEffect *blurEffect;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.imgView.userInteractionEnabled = YES;
UIImage *image = [UIImage imageNamed:@"BeauGir.jpg"];
self.imgView.image = image;
UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] init];
[longPressGR addTarget:self action:@selector(changeEffect:)];
[self.imgView addGestureRecognizer:longPressGR];
}
- (void)changeEffect:(UILongPressGestureRecognizer *)recognizer {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"改变效果" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self executeChangingEffect];
}];
[alertController addAction:confirmAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:NULL];
}
- (void)executeChangingEffect {
UIImage *image = [UIImage imageNamed:@"BeauGir.jpg"];
static int i = 0;
if (i == 0) {
self.imgView.image = [self.blurEffect blurryImage:image style:DYFBlurEffectLight];
} else if (i == 1) {
self.imgView.image = [self.blurEffect blurryImage:image tintColor:[UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1]];
} else if (i == 2) {
self.imgView.image = image;
UIVisualEffectView *blurView = [self.blurEffect blurViewWithStyle:UIBlurEffectStyleLight];
blurView.frame = self.imgView.bounds;
blurView.tag = 10;
blurView.userInteractionEnabled = YES;
[self.view addSubview:blurView];
UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] init];
[longPressGR addTarget:self action:@selector(changeEffect:)];
[blurView addGestureRecognizer:longPressGR];
} else {
self.imgView.image = [self.blurEffect coreImage:image blurRadius:10];
}
if (i != 2) {
UIVisualEffectView *blurView = [self.view viewWithTag:10];
!blurView ?: [blurView removeFromSuperview];
}
i++;
if (i >= 4) { i = 0; }
}
- (DYFBlurEffect *)blurEffect {
if (!_blurEffect) {
_blurEffect = [[DYFBlurEffect alloc] init];
}
return _blurEffect;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end