forked from sprang/Inkpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWDBlockingView.m
More file actions
69 lines (55 loc) · 1.99 KB
/
WDBlockingView.m
File metadata and controls
69 lines (55 loc) · 1.99 KB
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
//
// WDBlockingView.m
// Inkpad
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2010-2013 Steve Sprang
//
#import "WDBlockingView.h"
#import "WDUtilities.h"
@implementation WDBlockingView
@synthesize passthroughViews = passthroughViews_;
@synthesize action = action_;
@synthesize target = target_;
- (UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
point = [self convertPoint:point toView:nil];
for (UIView *view in passthroughViews_) {
CGPoint testPt = [view convertPoint:point fromView:nil];
if ([view hitTest:testPt withEvent:event]) {
return nil;
}
}
return [super hitTest:point withEvent:event];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
sendAction_ = YES;
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (sendAction_) {
[[UIApplication sharedApplication] sendAction:action_ to:target_ from:self forEvent:event];
}
}
- (void) setShadowCenter:(CGPoint)center radius:(float)radius
{
CALayer *layer = self.layer;
layer.shadowOpacity = 0.5;
layer.shadowRadius = 25;
layer.shadowOffset = CGSizeMake(0, 0);
CGPoint rectCenter = WDCenterOfRect(self.bounds);
// flip one of the paths so that we get a hole in the shadow
CGAffineTransform tX = CGAffineTransformMakeTranslation(rectCenter.x, rectCenter.y);
tX = CGAffineTransformScale(tX, 1, -1);
const CGAffineTransform flip = CGAffineTransformTranslate(tX, -rectCenter.x, -rectCenter.y);
CGMutablePathRef pathRef = CGPathCreateMutable();
CGPathAddRect(pathRef, &flip, CGRectInset(self.bounds, -50, -50));
CGPathAddEllipseInRect(pathRef, NULL, CGRectMake(center.x - radius, center.y - radius, radius * 2, radius * 2));
layer.shadowPath = pathRef;
CGPathRelease(pathRef);
}
@end