UIView+GestureCallback.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. // UIView+GestureCallback.h
  2. //
  3. // Created by Onur Ersel on 01/07/15.
  4. // Copyright (c) 2015 Onur Ersel. All rights reserved.
  5. //
  6. #import "UIView+GestureCallback.h"
  7. #import <objc/runtime.h>
  8. const NSString *UIView_GestureCallback_gesturesKey = @"UIView_GestureCallback_gesturesKey";
  9. const NSString *UIView_GestureCallback_gestureKeysHashKey = @"UIView_GestureCallback_gestureKeysHashKey";
  10. @implementation GestureCallbackValues
  11. @synthesize tapCallback, pinchCallback, panCallback, swipeCallback, rotationCallback, longPressCallback;
  12. @synthesize gesture, gestureId;
  13. @end
  14. @implementation UIView (GestureCallback)
  15. @dynamic gestures, gestureKeysHash;
  16. #pragma mark - ##### TAP
  17. #pragma mark add tap gestures
  18. -(NSString*)addTapGestureRecognizer:(void(^)(UITapGestureRecognizer* recognizer, NSString* gestureId))tapCallback
  19. {
  20. NSString *rand;
  21. do {
  22. rand = [self randomStringWithLength:12];
  23. } while ([self.gestures objectForKey:rand] != nil);
  24. [self addTapGestureRecognizer:tapCallback tapGestureId:rand];
  25. return rand;
  26. }
  27. -(NSString*)addTapGestureRecognizer:(void(^)(UITapGestureRecognizer* recognizer, NSString* gestureId))tapCallback numberOfTapsRequired:(NSUInteger)numberOfTapsRequired numberOfTouchesRequired:(NSUInteger)numberOfTouchesRequired
  28. {
  29. NSString *rand;
  30. do {
  31. rand = [self randomStringWithLength:12];
  32. } while ([self.gestures objectForKey:rand] != nil);
  33. [self addTapGestureRecognizer:tapCallback tapGestureId:rand numberOfTapsRequired:numberOfTapsRequired numberOfTouchesRequired:numberOfTouchesRequired];
  34. return rand;
  35. }
  36. -(void)addTapGestureRecognizer:(void(^)(UITapGestureRecognizer* recognizer, NSString* gestureId))tapCallback tapGestureId:(NSString*)tapGestureId
  37. {
  38. [self addTapGestureRecognizer:tapCallback tapGestureId:tapGestureId numberOfTapsRequired:1 numberOfTouchesRequired:1];
  39. }
  40. -(void)addTapGestureRecognizer:(void(^)(UITapGestureRecognizer* recognizer, NSString* gestureId))tapCallback tapGestureId:(NSString*)tapGestureId numberOfTapsRequired:(NSUInteger)numberOfTapsRequired numberOfTouchesRequired:(NSUInteger)numberOfTouchesRequired
  41. {
  42. UIGestureRecognizer *r = [self.gestures objectForKey:tapGestureId];
  43. if (r != nil) {
  44. [self removeTapGesture:tapGestureId];
  45. }
  46. UITapGestureRecognizer *tg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandler:)];
  47. tg.numberOfTapsRequired = numberOfTapsRequired;
  48. tg.numberOfTouchesRequired = numberOfTouchesRequired;
  49. GestureCallbackValues *v = [GestureCallbackValues new];
  50. v.gesture = tg;
  51. v.tapCallback = tapCallback;
  52. v.gestureId = tapGestureId;
  53. [self.gestureKeysHash setValue:v forKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  54. [self.gestures setValue:v forKey:tapGestureId];
  55. [self addGestureRecognizer:tg];
  56. }
  57. #pragma mark remove tap gestures
  58. -(void)removeTapGesture:(NSString*)tapGestureId
  59. {
  60. GestureCallbackValues *v = [self.gestures objectForKey:tapGestureId];
  61. if (v != nil) {
  62. [self.gestures removeObjectForKey:tapGestureId];
  63. [self.gestureKeysHash removeObjectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  64. [self removeGestureRecognizer:v.gesture];
  65. }
  66. }
  67. -(void)removeAllTapGestures
  68. {
  69. NSArray *arr = self.gestures.allValues;
  70. for (GestureCallbackValues *v in arr) {
  71. if ([v.gesture isMemberOfClass:[UITapGestureRecognizer class]]) {
  72. [self removeTapGesture:v.gestureId];
  73. }
  74. }
  75. }
  76. #pragma mark tap handler
  77. -(void)tapHandler:(UITapGestureRecognizer*)recognizer
  78. {
  79. GestureCallbackValues *v = [self.gestureKeysHash objectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)recognizer.hash]];
  80. if (v != nil) {
  81. if (v.tapCallback != nil) {
  82. v.tapCallback((UITapGestureRecognizer*)v.gesture, v.gestureId);
  83. }
  84. }
  85. }
  86. #pragma mark - ##### PINCH
  87. #pragma mark add pinch gestures
  88. -(NSString*)addPinchGestureRecognizer:(void(^)(UIPinchGestureRecognizer* recognizer, NSString* gestureId))pinchCallback
  89. {
  90. NSString *rand;
  91. do {
  92. rand = [self randomStringWithLength:12];
  93. } while ([self.gestures objectForKey:rand] != nil);
  94. [self addPinchGestureRecognizer:pinchCallback pinchGestureId:rand];
  95. return rand;
  96. }
  97. -(void)addPinchGestureRecognizer:(void(^)(UIPinchGestureRecognizer* recognizer, NSString* gestureId))pinchCallback pinchGestureId:(NSString*)pinchGestureId
  98. {
  99. UIGestureRecognizer *r = [self.gestures objectForKey:pinchGestureId];
  100. if (r != nil) {
  101. [self removePinchGesture:pinchGestureId];
  102. }
  103. UIPinchGestureRecognizer *tg = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchHandler:)];
  104. GestureCallbackValues *v = [GestureCallbackValues new];
  105. v.gesture = tg;
  106. v.pinchCallback = pinchCallback;
  107. v.gestureId = pinchGestureId;
  108. [self.gestureKeysHash setValue:v forKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  109. [self.gestures setValue:v forKey:pinchGestureId];
  110. [self addGestureRecognizer:tg];
  111. }
  112. #pragma mark remove pinch gestures
  113. -(void)removePinchGesture:(NSString*)pinchGestureId
  114. {
  115. GestureCallbackValues *v = [self.gestures objectForKey:pinchGestureId];
  116. if (v != nil) {
  117. [self.gestures removeObjectForKey:pinchGestureId];
  118. [self.gestureKeysHash removeObjectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  119. [self removeGestureRecognizer:v.gesture];
  120. }
  121. }
  122. -(void)removeAllPinchGestures
  123. {
  124. NSArray *arr = self.gestures.allValues;
  125. for (GestureCallbackValues *v in arr) {
  126. if ([v.gesture isMemberOfClass:[UIPinchGestureRecognizer class]]) {
  127. [self removePinchGesture:v.gestureId];
  128. }
  129. }
  130. }
  131. #pragma mark pinch handler
  132. -(void)pinchHandler:(UIPinchGestureRecognizer*)recognizer
  133. {
  134. GestureCallbackValues *v = [self.gestureKeysHash objectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)recognizer.hash]];
  135. if (v != nil) {
  136. if (v.pinchCallback != nil) {
  137. v.pinchCallback((UIPinchGestureRecognizer*)v.gesture, v.gestureId);
  138. }
  139. }
  140. }
  141. #pragma mark - ##### PAN
  142. #pragma mark add pan gestures
  143. -(NSString*)addPanGestureRecognizer:(void(^)(UIPanGestureRecognizer* recognizer, NSString* gestureId))panCallback
  144. {
  145. return [self addPanGestureRecognizer:panCallback minimumNumberOfTouches:1 maximumNumberOfTouches:NSUIntegerMax];
  146. }
  147. -(NSString*)addPanGestureRecognizer:(void(^)(UIPanGestureRecognizer* recognizer, NSString* gestureId))panCallback minimumNumberOfTouches:(NSUInteger)minimumNumberOfTouches maximumNumberOfTouches:(NSUInteger)maximumNumberOfTouches
  148. {
  149. NSString *rand;
  150. do {
  151. rand = [self randomStringWithLength:12];
  152. } while ([self.gestures objectForKey:rand] != nil);
  153. [self addPanGestureRecognizer:panCallback panGestureId:rand minimumNumberOfTouches:minimumNumberOfTouches maximumNumberOfTouches:maximumNumberOfTouches];
  154. return rand;
  155. }
  156. -(void)addPanGestureRecognizer:(void(^)(UIPanGestureRecognizer* recognizer, NSString* gestureId))panCallback panGestureId:(NSString*)panGestureId minimumNumberOfTouches:(NSUInteger)minimumNumberOfTouches maximumNumberOfTouches:(NSUInteger)maximumNumberOfTouches
  157. {
  158. UIGestureRecognizer *r = [self.gestures objectForKey:panGestureId];
  159. if (r != nil) {
  160. [self removePanGesture:panGestureId];
  161. }
  162. UIPanGestureRecognizer *tg = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panHandler:)];
  163. tg.minimumNumberOfTouches = minimumNumberOfTouches;
  164. tg.maximumNumberOfTouches = maximumNumberOfTouches;
  165. GestureCallbackValues *v = [GestureCallbackValues new];
  166. v.gesture = tg;
  167. v.panCallback = panCallback;
  168. v.gestureId = panGestureId;
  169. [self.gestureKeysHash setValue:v forKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  170. [self.gestures setValue:v forKey:panGestureId];
  171. [self addGestureRecognizer:tg];
  172. }
  173. #pragma mark remove pan gestures
  174. -(void)removePanGesture:(NSString*)panGestureId
  175. {
  176. GestureCallbackValues *v = [self.gestures objectForKey:panGestureId];
  177. if (v != nil) {
  178. [self.gestures removeObjectForKey:panGestureId];
  179. [self.gestureKeysHash removeObjectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  180. [self removeGestureRecognizer:v.gesture];
  181. }
  182. }
  183. -(void)removeAllPanGestures
  184. {
  185. NSArray *arr = self.gestures.allValues;
  186. for (GestureCallbackValues *v in arr) {
  187. if ([v.gesture isMemberOfClass:[UIPanGestureRecognizer class]]) {
  188. [self removePanGesture:v.gestureId];
  189. }
  190. }
  191. }
  192. #pragma mark pan handler
  193. -(void)panHandler:(UIPanGestureRecognizer*)recognizer
  194. {
  195. GestureCallbackValues *v = [self.gestureKeysHash objectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)recognizer.hash]];
  196. if (v != nil) {
  197. if (v.panCallback != nil) {
  198. v.panCallback((UIPanGestureRecognizer*)v.gesture, v.gestureId);
  199. }
  200. }
  201. }
  202. #pragma mark - ##### SWIPE
  203. -(NSString*)addSwipeGestureRecognizer:(void(^)(UISwipeGestureRecognizer* recognizer, NSString* gestureId))swipeCallback direction:(UISwipeGestureRecognizerDirection)direction
  204. {
  205. return [self addSwipeGestureRecognizer:swipeCallback direction:direction numberOfTouchesRequired:1];
  206. }
  207. -(NSString*)addSwipeGestureRecognizer:(void(^)(UISwipeGestureRecognizer* recognizer, NSString* gestureId))swipeCallback direction:(UISwipeGestureRecognizerDirection)direction numberOfTouchesRequired:(NSUInteger)numberOfTouchesRequired
  208. {
  209. NSString *rand;
  210. do {
  211. rand = [self randomStringWithLength:12];
  212. } while ([self.gestures objectForKey:rand] != nil);
  213. [self addSwipeGestureRecognizer:swipeCallback swipeGestureId:rand direction:direction numberOfTouchesRequired:numberOfTouchesRequired];
  214. return rand;
  215. }
  216. -(void)addSwipeGestureRecognizer:(void(^)(UISwipeGestureRecognizer* recognizer, NSString* gestureId))swipeCallback swipeGestureId:(NSString*)swipeGestureId direction:(UISwipeGestureRecognizerDirection)direction numberOfTouchesRequired:(NSUInteger)numberOfTouchesRequired
  217. {
  218. UIGestureRecognizer *r = [self.gestures objectForKey:swipeGestureId];
  219. if (r != nil) {
  220. [self removeSwipeGesture:swipeGestureId];
  221. }
  222. UISwipeGestureRecognizer *tg = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
  223. tg.direction = direction;
  224. tg.numberOfTouchesRequired = numberOfTouchesRequired;
  225. GestureCallbackValues *v = [GestureCallbackValues new];
  226. v.gesture = tg;
  227. v.swipeCallback = swipeCallback;
  228. v.gestureId = swipeGestureId;
  229. [self.gestureKeysHash setValue:v forKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  230. [self.gestures setValue:v forKey:swipeGestureId];
  231. [self addGestureRecognizer:tg];
  232. }
  233. #pragma mark remove swipe gestures
  234. -(void)removeSwipeGesture:(NSString*)swipeGestureId
  235. {
  236. GestureCallbackValues *v = [self.gestures objectForKey:swipeGestureId];
  237. if (v != nil) {
  238. [self.gestures removeObjectForKey:swipeGestureId];
  239. [self.gestureKeysHash removeObjectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  240. [self removeGestureRecognizer:v.gesture];
  241. }
  242. }
  243. -(void)removeAllSwipeGestures
  244. {
  245. NSArray *arr = self.gestures.allValues;
  246. for (GestureCallbackValues *v in arr) {
  247. if ([v.gesture isMemberOfClass:[UISwipeGestureRecognizer class]]) {
  248. [self removeSwipeGesture:v.gestureId];
  249. }
  250. }
  251. }
  252. #pragma mark swipe handler
  253. -(void)swipeHandler:(UISwipeGestureRecognizer*)recognizer
  254. {
  255. GestureCallbackValues *v = [self.gestureKeysHash objectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)recognizer.hash]];
  256. if (v != nil) {
  257. if (v.swipeCallback != nil) {
  258. v.swipeCallback((UISwipeGestureRecognizer*)v.gesture, v.gestureId);
  259. }
  260. }
  261. }
  262. #pragma mark - ##### ROTATION
  263. #pragma mark add rotation gestures
  264. -(NSString*)addRotationGestureRecognizer:(void(^)(UIRotationGestureRecognizer* recognizer, NSString* gestureId))rotationCallback
  265. {
  266. NSString *rand;
  267. do {
  268. rand = [self randomStringWithLength:12];
  269. } while ([self.gestures objectForKey:rand] != nil);
  270. [self addRotationGestureRecognizer:rotationCallback rotationGestureId:rand];
  271. return rand;
  272. }
  273. -(void)addRotationGestureRecognizer:(void(^)(UIRotationGestureRecognizer* recognizer, NSString* gestureId))rotationCallback rotationGestureId:(NSString*)rotationGestureId
  274. {
  275. UIGestureRecognizer *r = [self.gestures objectForKey:rotationGestureId];
  276. if (r != nil) {
  277. [self removeRotationGesture:rotationGestureId];
  278. }
  279. UIRotationGestureRecognizer *tg = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationHandler:)];
  280. GestureCallbackValues *v = [GestureCallbackValues new];
  281. v.gesture = tg;
  282. v.rotationCallback = rotationCallback;
  283. v.gestureId = rotationGestureId;
  284. [self.gestureKeysHash setValue:v forKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  285. [self.gestures setValue:v forKey:rotationGestureId];
  286. [self addGestureRecognizer:tg];
  287. }
  288. #pragma mark remove rotation gestures
  289. -(void)removeRotationGesture:(NSString*)rotationGestureId
  290. {
  291. GestureCallbackValues *v = [self.gestures objectForKey:rotationGestureId];
  292. if (v != nil) {
  293. [self.gestures removeObjectForKey:rotationGestureId];
  294. [self.gestureKeysHash removeObjectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  295. [self removeGestureRecognizer:v.gesture];
  296. }
  297. }
  298. -(void)removeAllRotationGestures
  299. {
  300. NSArray *arr = self.gestures.allValues;
  301. for (GestureCallbackValues *v in arr) {
  302. if ([v.gesture isMemberOfClass:[UIRotationGestureRecognizer class]]) {
  303. [self removeRotationGesture:v.gestureId];
  304. }
  305. }
  306. }
  307. #pragma mark rotation handler
  308. -(void)rotationHandler:(UIRotationGestureRecognizer*)recognizer
  309. {
  310. GestureCallbackValues *v = [self.gestureKeysHash objectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)recognizer.hash]];
  311. if (v != nil) {
  312. if (v.rotationCallback != nil) {
  313. v.rotationCallback((UIRotationGestureRecognizer*)v.gesture, v.gestureId);
  314. }
  315. }
  316. }
  317. #pragma mark - ##### LONG PRESS
  318. #pragma mark add longPress gestures
  319. -(NSString*)addLongPressGestureRecognizer:(void(^)(UILongPressGestureRecognizer* recognizer, NSString* gestureId))longPressCallback
  320. {
  321. return [self addLongPressGestureRecognizer:longPressCallback numberOfTapsRequired:0 numberOfTouchesRequired:1 minimumPressDuration:0.5 allowableMovement:10];
  322. }
  323. -(NSString*)addLongPressGestureRecognizer:(void(^)(UILongPressGestureRecognizer* recognizer, NSString* gestureId))longPressCallback
  324. numberOfTapsRequired:(NSUInteger)numberOfTapsRequired
  325. numberOfTouchesRequired:(NSUInteger)numberOfTouchesRequired
  326. minimumPressDuration:(CFTimeInterval)minimumPressDuration
  327. allowableMovement:(CGFloat)allowableMovement
  328. {
  329. NSString *rand;
  330. do {
  331. rand = [self randomStringWithLength:12];
  332. } while ([self.gestures objectForKey:rand] != nil);
  333. [self addLongPressGestureRecognizer:longPressCallback longPressGestureId:rand numberOfTapsRequired:numberOfTapsRequired numberOfTouchesRequired:numberOfTouchesRequired minimumPressDuration:minimumPressDuration allowableMovement:allowableMovement];
  334. return rand;
  335. }
  336. -(void)addLongPressGestureRecognizer:(void(^)(UILongPressGestureRecognizer* recognizer, NSString* gestureId))longPressCallback
  337. longPressGestureId:(NSString*)longPressGestureId
  338. numberOfTapsRequired:(NSUInteger)numberOfTapsRequired
  339. numberOfTouchesRequired:(NSUInteger)numberOfTouchesRequired
  340. minimumPressDuration:(CFTimeInterval)minimumPressDuration
  341. allowableMovement:(CGFloat)allowableMovement
  342. {
  343. UIGestureRecognizer *r = [self.gestures objectForKey:longPressGestureId];
  344. if (r != nil) {
  345. [self removeLongPressGesture:longPressGestureId];
  346. }
  347. UILongPressGestureRecognizer *tg = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
  348. tg.numberOfTapsRequired = numberOfTapsRequired;
  349. tg.numberOfTouchesRequired = numberOfTouchesRequired;
  350. tg.minimumPressDuration = minimumPressDuration;
  351. tg.allowableMovement = allowableMovement;
  352. GestureCallbackValues *v = [GestureCallbackValues new];
  353. v.gesture = tg;
  354. v.longPressCallback = longPressCallback;
  355. v.gestureId = longPressGestureId;
  356. [self.gestureKeysHash setValue:v forKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  357. [self.gestures setValue:v forKey:longPressGestureId];
  358. [self addGestureRecognizer:tg];
  359. }
  360. #pragma mark remove longPress gestures
  361. -(void)removeLongPressGesture:(NSString*)longPressGestureId
  362. {
  363. GestureCallbackValues *v = [self.gestures objectForKey:longPressGestureId];
  364. if (v != nil) {
  365. [self.gestures removeObjectForKey:longPressGestureId];
  366. [self.gestureKeysHash removeObjectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)v.gesture.hash]];
  367. [self removeGestureRecognizer:v.gesture];
  368. }
  369. }
  370. -(void)removeAllLongPressGestures
  371. {
  372. NSArray *arr = self.gestures.allValues;
  373. for (GestureCallbackValues *v in arr) {
  374. if ([v.gesture isMemberOfClass:[UILongPressGestureRecognizer class]]) {
  375. [self removeLongPressGesture:v.gestureId];
  376. }
  377. }
  378. }
  379. #pragma mark longPress handler
  380. -(void)longPressHandler:(UILongPressGestureRecognizer*)recognizer
  381. {
  382. GestureCallbackValues *v = [self.gestureKeysHash objectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)recognizer.hash]];
  383. if (v != nil) {
  384. if (v.longPressCallback != nil) {
  385. v.longPressCallback((UILongPressGestureRecognizer*)v.gesture, v.gestureId);
  386. }
  387. }
  388. }
  389. #pragma mark - random string
  390. /*----------------------------------
  391. *
  392. * A random string implementation from
  393. * http://stackoverflow.com/questions/2633801/generate-a-random-alphanumeric-string-in-cocoa
  394. *
  395. ---------------------------------*/
  396. -(NSString *) randomStringWithLength: (int) len {
  397. const NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  398. NSMutableString *randomString = [NSMutableString stringWithCapacity: len];
  399. for (int i=0; i<len; i++) {
  400. [randomString appendFormat: @"%C", [letters characterAtIndex: arc4random_uniform((u_int32_t)[letters length])]];
  401. }
  402. return randomString;
  403. }
  404. #pragma mark - getter/setters
  405. -(NSMutableDictionary *)gestures {
  406. NSMutableDictionary *dict = objc_getAssociatedObject(self, &UIView_GestureCallback_gesturesKey);
  407. if (dict == nil) {
  408. dict = [NSMutableDictionary new];
  409. self.gestures = dict;
  410. }
  411. return dict;
  412. }
  413. -(void) setGestures:(NSMutableDictionary *)value
  414. {
  415. objc_setAssociatedObject(self, &UIView_GestureCallback_gesturesKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  416. }
  417. -(NSMutableDictionary *)gestureKeysHash {
  418. NSMutableDictionary *dict = objc_getAssociatedObject(self, &UIView_GestureCallback_gestureKeysHashKey);
  419. if (dict == nil) {
  420. dict = [NSMutableDictionary new];
  421. self.gestureKeysHash = dict;
  422. }
  423. return dict;
  424. }
  425. -(void) setGestureKeysHash:(NSMutableDictionary *)value
  426. {
  427. objc_setAssociatedObject(self, &UIView_GestureCallback_gestureKeysHashKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  428. }
  429. //TODO : CustomGestureRecognizer
  430. @end