forked from alvises/FPPopover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPTouchView.m
66 lines (55 loc) · 1.33 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
//
// 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"
@implementation FPTouchView
-(void)dealloc
{
[_outsideBlock release];
[_insideBlock release];
[super dealloc];
}
-(void)setTouchedOutsideBlock:(FPTouchedOutsideBlock)outsideBlock
{
[_outsideBlock release];
_outsideBlock = [outsideBlock copy];
}
-(void)setTouchedInsideBlock:(FPTouchedInsideBlock)insideBlock
{
[_insideBlock release];
_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