-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFTouchableView.m
executable file
·110 lines (85 loc) · 2.61 KB
/
FFTouchableView.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
103
104
105
106
107
108
109
110
//
// WETouchableView.m
// WEPopover
//
// Created by Werner Altewischer on 12/21/10.
// Copyright 2010 Werner IT Consultancy. All rights reserved.
//
#import "FFTouchableView.h"
#import "FFBlockingGestureRecognizer.h"
@interface FFTouchableView()
@end
@interface FFTouchableView(Private)
- (BOOL)isPassthroughView:(UIView *)v;
@end
@implementation FFTouchableView {
BOOL _testHits;
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
FFBlockingGestureRecognizer *gr = [[FFBlockingGestureRecognizer alloc] init];
[self addGestureRecognizer:gr];
self.backgroundColor = [UIColor clearColor];
self.fillView = [[UIView alloc] init];
self.fillView.backgroundColor = [UIColor clearColor];
[self addSubview:self.fillView];
}
return self;
}
- (void)setFillView:(UIView *)fillView {
if (_fillView != fillView) {
[_fillView removeFromSuperview];
_fillView = fillView;
if (_fillView != nil) {
[self addSubview:_fillView];
[self setNeedsLayout];
}
}
}
- (void)setFillColor:(UIColor *)fillColor {
self.fillView.backgroundColor = fillColor;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect fillRect = self.bounds;
if ([self.delegate respondsToSelector:@selector(fillRectForView:)]) {
fillRect = [self.delegate fillRectForView:self];
}
self.fillView.frame = fillRect;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (_testHits) {
return nil;
} else if (_touchForwardingDisabled) {
return self;
} else {
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self || hitView == self.fillView) {
//Test whether any of the passthrough views would handle this touch
_testHits = YES;
UIView *superHitView = [self.superview hitTest:point withEvent:event];
_testHits = NO;
if ([self isPassthroughView:superHitView]) {
hitView = superHitView;
}
}
return hitView;
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ([self.delegate respondsToSelector:@selector(viewWasTouched:)]) {
[self.delegate viewWasTouched:self];
}
}
@end
@implementation FFTouchableView(Private)
- (BOOL)isPassthroughView:(UIView *)v {
if (v == nil) {
return NO;
}
if ([_passthroughViews containsObject:v]) {
return YES;
}
return [self isPassthroughView:v.superview];
}
@end