forked from brightsoftdev/Additions-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIGestureRecognizer+Additions.m
48 lines (37 loc) · 1009 Bytes
/
UIGestureRecognizer+Additions.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
//
// UIGestureRecognizer+Additions.m
//
// Created by Wess Cope on 6/3/11.
// Copyright 2012. All rights reserved.
//
#import "UIGestureRecognizer+Additions.h"
#import <objc/runtime.h>
@interface UIGestureRecognizer(Private)
- (void) executeCallback:(id)sender;
@end
@implementation UIGestureRecognizer(Additions)
+ (id)withCallback:(GestureCallback)aCallback
{
return [[[[self class] alloc] initWithCallback:aCallback] autorelease];
}
- (id)initWithCallback:(GestureCallback)aCallback
{
self = [self initWithTarget:self action:@selector(executeCallback:)];
[self setCallback:aCallback];
return self;
}
- (void) executeCallback:(id)sender
{
GestureCallback tmpCallback = self.callback;
if(tmpCallback)
tmpCallback(self);
}
- (void)setCallback:(GestureCallback)aCallback
{
objc_setAssociatedObject(self, @"gCallback_", aCallback, OBJC_ASSOCIATION_COPY);
}
- (GestureCallback)callback
{
return objc_getAssociatedObject(self, @"gCallback_");
}
@end