-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCComparatorView.m
66 lines (50 loc) · 2.09 KB
/
CCComparatorView.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
//
// CCComparatorView.h
//
// Created by Gustavo Grana on 7/3/12.
//
#import "CCComparatorView.h"
@implementation CCComparatorView
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
UIView* touchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAlphaChange:)];
[pan setMaximumNumberOfTouches:1];
UIPanGestureRecognizer* panRemove = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRemove:)];
[panRemove setMinimumNumberOfTouches:2];
[self setBackgroundColor:[UIColor clearColor]];
[touchView addGestureRecognizer:panRemove];
[touchView addGestureRecognizer:pan];
[self addSubview:touchView];
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
UIView* touchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAlphaChange:)];
[pan setMaximumNumberOfTouches:1];
UIPanGestureRecognizer* panRemove = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRemove:)];
[panRemove setMinimumNumberOfTouches:2];
[self setBackgroundColor:[UIColor clearColor]];
[touchView addGestureRecognizer:panRemove];
[touchView addGestureRecognizer:pan];
[self addSubview:touchView];
}
return self;
}
- (void) gestureAlphaChange:(UIPanGestureRecognizer*)pan {
CGPoint velocity = [pan velocityInView:self];
if (velocity.y < 0) {
self.alpha = self.alpha == 1 ? 1 : self.alpha + 0.01;
} else {
self.alpha = self.alpha < 0.05 ? 0.05 : self.alpha - 0.01;
}
}
- (void) gestureRemove:(UIPanGestureRecognizer*)pan {
self.alpha = 0;
}
@end