-
Notifications
You must be signed in to change notification settings - Fork 250
/
FPTouchView.m
71 lines (59 loc) · 1.45 KB
/
FPTouchView.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
//
// FPTouchView.m
//
// Created by Alvise Susmel on 4/16/12.
// Copyright (c) 2012 Fifty Pixels Ltd. All rights reserved.
//
// https://github.com/50pixels/FPPopover
#import "FPTouchView.h"
#import "ARCMacros.h"
@implementation FPTouchView
-(void)dealloc
{
#ifdef FP_DEBUG
NSLog(@"FPTouchView dealloc");
#endif
SAFE_ARC_RELEASE(_insideBlock);
SAFE_ARC_RELEASE(_outsideBlock);
SAFE_ARC_SUPER_DEALLOC();
}
-(void)setTouchedOutsideBlock:(FPTouchedOutsideBlock)outsideBlock
{
SAFE_ARC_RELEASE(_outsideBlock);
_outsideBlock = [outsideBlock copy];
}
-(void)setTouchedInsideBlock:(FPTouchedInsideBlock)insideBlock
{
SAFE_ARC_RELEASE(_insideBlock);
_insideBlock = [insideBlock copy];
}
-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *subview = [super hitTest:point withEvent:event];
if(UIEventTypeTouches == event.type)
{
BOOL touchedInside = subview != self;
if(!touchedInside)
{
for(UIView *s in self.subviews)
{
if(s == subview)
{
//touched inside
touchedInside = YES;
break;
}
}
}
if(touchedInside && _insideBlock)
{
_insideBlock();
}
else if(!touchedInside && _outsideBlock)
{
_outsideBlock();
}
}
return subview;
}
@end