/BlocksKit/UIView+BlocksKit.h

http://github.com/zwaldowski/BlocksKit · C Header · 94 lines · 10 code · 10 blank · 74 comment · 0 complexity · ec040ac3cb49ad0e7c01d676059b3cea MD5 · raw file

  1. //
  2. // UIView+BlocksKit.h
  3. // %PROJECT
  4. //
  5. #import "BKGlobals.h"
  6. /** Convenience on-touch methods for UIView.
  7. Includes code by the following:
  8. - Kevin O'Neill. <https://github.com/kevinoneill>. 2011. BSD.
  9. - Jake Marsh. <https://github.com/jakemarsh>. 2011.
  10. - Zach Waldowski. <https://github.com/zwaldowski>. 2011. MIT.
  11. @warning UIView is only available on iOS or in a Mac app using Chameleon.
  12. */
  13. @interface UIView (BlocksKit)
  14. /** Abstract creation of a block-backed UITapGestureRecognizer.
  15. This method allows for the recognition of any arbitrary number
  16. of fingers tapping any number of times on a view. An instance
  17. of UITapGesture recognizer is allocated for the block and added
  18. to the recieving view.
  19. @warning This method has an _additive_ effect. Do not call it multiple
  20. times to set-up or tear-down. The view will discard the gesture recognizer
  21. on release.
  22. @param numberOfTouches The number of fingers tapping that will trigger the block.
  23. @param numberOfTaps The number of taps required to trigger the block.
  24. @param block The handler for the UITapGestureRecognizer
  25. @see whenTapped:
  26. @see whenDoubleTapped:
  27. */
  28. - (void)whenTouches:(NSUInteger)numberOfTouches tapped:(NSUInteger)numberOfTaps handler:(BKBlock)block;
  29. /** Adds a recognizer for one finger tapping once.
  30. @warning This method has an _additive_ effect. Do not call it multiple
  31. times to set-up or tear-down. The view will discard the gesture recognizer
  32. on release.
  33. @param block The handler for the tap recognizer
  34. @see whenDoubleTapped:
  35. @see whenTouches:tapped:handler:
  36. */
  37. - (void)whenTapped:(BKBlock)block;
  38. /** Adds a recognizer for one finger tapping twice.
  39. @warning This method has an _additive_ effect. Do not call it multiple
  40. times to set-up or tear-down. The view will discard the gesture recognizer
  41. on release.
  42. @param block The handler for the tap recognizer
  43. @see whenTapped:
  44. @see whenTouches:tapped:handler:
  45. */
  46. - (void)whenDoubleTapped:(BKBlock)block;
  47. /** A convenience wrapper that non-recursively loops through the subviews of a view.
  48. @param block A code block that interacts with a UIView sender.
  49. */
  50. - (void)eachSubview:(void(^)(UIView *))block;
  51. /** The block that gets called on a finger down.
  52. Internally, this method overrides the touchesBegan:withEvent:
  53. selector of UIView and is mechanically similar to
  54. UIControlEventTouchDown.
  55. */
  56. @property (nonatomic, copy) BKTouchBlock onTouchDownBlock;
  57. /** The block that gets called on a finger drag.
  58. Internally, this method overrides the touchesMoved:withEvent:
  59. selector of UIView.
  60. @param block The handler for the touch recognizer
  61. */
  62. @property (nonatomic, copy) BKTouchBlock onTouchMoveBlock;
  63. /** The block that gets called on a finger up.
  64. Internally, this method overrides the touchesBegan:withEvent:
  65. selector of UIView and is mechanically similar to
  66. UIControlEventTouchCancel.
  67. */
  68. @property (nonatomic, copy) BKTouchBlock onTouchUpBlock;
  69. @end