UIView+BlocksKit.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // UIView+BlocksKit.h
  3. // BlocksKit
  4. //
  5. #import <UIKit/UIKit.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.
  11. @warning UIView is only available on a platform with UIKit.
  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)bk_whenTouches:(NSUInteger)numberOfTouches tapped:(NSUInteger)numberOfTaps handler:(void (^)(void))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)bk_whenTapped:(void (^)(void))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)bk_whenDoubleTapped:(void (^)(void))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)bk_eachSubview:(void (^)(UIView *subview))block;
  51. @end