ZFPlayerGestureControl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // ZFPlayerGestureControl.h
  3. // ZFPlayer
  4. //
  5. // Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. #import <UIKit/UIKit.h>
  25. NS_ASSUME_NONNULL_BEGIN
  26. typedef NS_ENUM(NSUInteger, ZFPlayerGestureType) {
  27. ZFPlayerGestureTypeUnknown,
  28. ZFPlayerGestureTypeSingleTap,
  29. ZFPlayerGestureTypeDoubleTap,
  30. ZFPlayerGestureTypePan,
  31. ZFPlayerGestureTypePinch
  32. };
  33. typedef NS_ENUM(NSUInteger, ZFPanDirection) {
  34. ZFPanDirectionUnknown,
  35. ZFPanDirectionV,
  36. ZFPanDirectionH,
  37. };
  38. typedef NS_ENUM(NSUInteger, ZFPanLocation) {
  39. ZFPanLocationUnknown,
  40. ZFPanLocationLeft,
  41. ZFPanLocationRight,
  42. };
  43. typedef NS_ENUM(NSUInteger, ZFPanMovingDirection) {
  44. ZFPanMovingDirectionUnkown,
  45. ZFPanMovingDirectionTop,
  46. ZFPanMovingDirectionLeft,
  47. ZFPanMovingDirectionBottom,
  48. ZFPanMovingDirectionRight,
  49. };
  50. /// This enumeration lists some of the gesture types that the player has by default.
  51. typedef NS_OPTIONS(NSUInteger, ZFPlayerDisableGestureTypes) {
  52. ZFPlayerDisableGestureTypesNone = 0,
  53. ZFPlayerDisableGestureTypesSingleTap = 1 << 0,
  54. ZFPlayerDisableGestureTypesDoubleTap = 1 << 1,
  55. ZFPlayerDisableGestureTypesPan = 1 << 2,
  56. ZFPlayerDisableGestureTypesPinch = 1 << 3,
  57. ZFPlayerDisableGestureTypesAll = (ZFPlayerDisableGestureTypesSingleTap | ZFPlayerDisableGestureTypesDoubleTap | ZFPlayerDisableGestureTypesPan | ZFPlayerDisableGestureTypesPinch)
  58. };
  59. /// This enumeration lists some of the pan gesture moving direction that the player not support.
  60. typedef NS_OPTIONS(NSUInteger, ZFPlayerDisablePanMovingDirection) {
  61. ZFPlayerDisablePanMovingDirectionNone = 0, /// Not disable pan moving direction.
  62. ZFPlayerDisablePanMovingDirectionVertical = 1 << 0, /// Disable pan moving vertical direction.
  63. ZFPlayerDisablePanMovingDirectionHorizontal = 1 << 1, /// Disable pan moving horizontal direction.
  64. ZFPlayerDisablePanMovingDirectionAll = (ZFPlayerDisablePanMovingDirectionVertical | ZFPlayerDisablePanMovingDirectionHorizontal) /// Disable pan moving all direction.
  65. };
  66. @interface ZFPlayerGestureControl : NSObject
  67. /// Gesture condition callback.
  68. @property (nonatomic, copy, nullable) BOOL(^triggerCondition)(ZFPlayerGestureControl *control, ZFPlayerGestureType type, UIGestureRecognizer *gesture, UITouch *touch);
  69. /// Single tap gesture callback.
  70. @property (nonatomic, copy, nullable) void(^singleTapped)(ZFPlayerGestureControl *control);
  71. /// Double tap gesture callback.
  72. @property (nonatomic, copy, nullable) void(^doubleTapped)(ZFPlayerGestureControl *control);
  73. /// Begin pan gesture callback.
  74. @property (nonatomic, copy, nullable) void(^beganPan)(ZFPlayerGestureControl *control, ZFPanDirection direction, ZFPanLocation location);
  75. /// Pan gesture changing callback.
  76. @property (nonatomic, copy, nullable) void(^changedPan)(ZFPlayerGestureControl *control, ZFPanDirection direction, ZFPanLocation location, CGPoint velocity);
  77. /// End the Pan gesture callback.
  78. @property (nonatomic, copy, nullable) void(^endedPan)(ZFPlayerGestureControl *control, ZFPanDirection direction, ZFPanLocation location);
  79. /// Pinch gesture callback.
  80. @property (nonatomic, copy, nullable) void(^pinched)(ZFPlayerGestureControl *control, float scale);
  81. /// The single tap gesture.
  82. @property (nonatomic, strong, readonly) UITapGestureRecognizer *singleTap;
  83. /// The double tap gesture.
  84. @property (nonatomic, strong, readonly) UITapGestureRecognizer *doubleTap;
  85. /// The pan tap gesture.
  86. @property (nonatomic, strong, readonly) UIPanGestureRecognizer *panGR;
  87. /// The pinch tap gesture.
  88. @property (nonatomic, strong, readonly) UIPinchGestureRecognizer *pinchGR;
  89. /// The pan gesture direction.
  90. @property (nonatomic, readonly) ZFPanDirection panDirection;
  91. /// The pan location.
  92. @property (nonatomic, readonly) ZFPanLocation panLocation;
  93. /// The moving drection.
  94. @property (nonatomic, readonly) ZFPanMovingDirection panMovingDirection;
  95. /// The gesture types that the player not support.
  96. @property (nonatomic) ZFPlayerDisableGestureTypes disableTypes;
  97. /// The pan gesture moving direction that the player not support.
  98. @property (nonatomic) ZFPlayerDisablePanMovingDirection disablePanMovingDirection;
  99. /**
  100. Add all gestures(singleTap、doubleTap、panGR、pinchGR) to the view.
  101. */
  102. - (void)addGestureToView:(UIView *)view;
  103. /**
  104. Remove all gestures(singleTap、doubleTap、panGR、pinchGR) form the view.
  105. */
  106. - (void)removeGestureToView:(UIView *)view;
  107. @end
  108. NS_ASSUME_NONNULL_END