UIScrollView+ZFPlayer.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // UIScrollView+ZFPlayer.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. /*
  27. * The scroll direction of scrollView.
  28. */
  29. typedef NS_ENUM(NSUInteger, ZFPlayerScrollDirection) {
  30. ZFPlayerScrollDirectionNone,
  31. ZFPlayerScrollDirectionUp, // Scroll up
  32. ZFPlayerScrollDirectionDown, // Scroll Down
  33. ZFPlayerScrollDirectionLeft, // Scroll left
  34. ZFPlayerScrollDirectionRight // Scroll right
  35. };
  36. /*
  37. * The scrollView direction.
  38. */
  39. typedef NS_ENUM(NSInteger, ZFPlayerScrollViewDirection) {
  40. ZFPlayerScrollViewDirectionVertical,
  41. ZFPlayerScrollViewDirectionHorizontal
  42. };
  43. /*
  44. * The player container type
  45. */
  46. typedef NS_ENUM(NSInteger, ZFPlayerContainerType) {
  47. ZFPlayerContainerTypeView,
  48. ZFPlayerContainerTypeCell
  49. };
  50. @interface UIScrollView (ZFPlayer)
  51. /// When the ZFPlayerScrollViewDirection is ZFPlayerScrollViewDirectionVertical,the property has value.
  52. @property (nonatomic, readonly) CGFloat zf_lastOffsetY;
  53. /// When the ZFPlayerScrollViewDirection is ZFPlayerScrollViewDirectionHorizontal,the property has value.
  54. @property (nonatomic, readonly) CGFloat zf_lastOffsetX;
  55. /// The scrollView scroll direction, default is ZFPlayerScrollViewDirectionVertical.
  56. @property (nonatomic) ZFPlayerScrollViewDirection zf_scrollViewDirection;
  57. /// The scroll direction of scrollView while scrolling.
  58. /// When the ZFPlayerScrollViewDirection is ZFPlayerScrollViewDirectionVertical,this value can only be ZFPlayerScrollDirectionUp or ZFPlayerScrollDirectionDown.
  59. /// When the ZFPlayerScrollViewDirection is ZFPlayerScrollViewDirectionVertical,this value can only be ZFPlayerScrollDirectionLeft or ZFPlayerScrollDirectionRight.
  60. @property (nonatomic, readonly) ZFPlayerScrollDirection zf_scrollDirection;
  61. /// Get the cell according to indexPath.
  62. - (UIView *)zf_getCellForIndexPath:(NSIndexPath *)indexPath;
  63. /// Get the indexPath for cell.
  64. - (NSIndexPath *)zf_getIndexPathForCell:(UIView *)cell;
  65. /// Scroll to indexPath with animations.
  66. - (void)zf_scrollToRowAtIndexPath:(NSIndexPath *)indexPath completionHandler:(void (^ __nullable)(void))completionHandler;
  67. /// add in 3.2.4 version.
  68. /// Scroll to indexPath with animations.
  69. - (void)zf_scrollToRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated completionHandler:(void (^ __nullable)(void))completionHandler;
  70. /// add in 3.2.8 version.
  71. /// Scroll to indexPath with animations duration.
  72. - (void)zf_scrollToRowAtIndexPath:(NSIndexPath *)indexPath animateWithDuration:(NSTimeInterval)duration completionHandler:(void (^ __nullable)(void))completionHandler;
  73. ///------------------------------------
  74. /// The following method must be implemented in UIScrollViewDelegate.
  75. ///------------------------------------
  76. - (void)zf_scrollViewDidEndDecelerating;
  77. - (void)zf_scrollViewDidEndDraggingWillDecelerate:(BOOL)decelerate;
  78. - (void)zf_scrollViewDidScrollToTop;
  79. - (void)zf_scrollViewDidScroll;
  80. - (void)zf_scrollViewWillBeginDragging;
  81. ///------------------------------------
  82. /// end
  83. ///------------------------------------
  84. @end
  85. @interface UIScrollView (ZFPlayerCannotCalled)
  86. /// The block invoked When the player appearing.
  87. @property (nonatomic, copy, nullable) void(^zf_playerAppearingInScrollView)(NSIndexPath *indexPath, CGFloat playerApperaPercent);
  88. /// The block invoked When the player disappearing.
  89. @property (nonatomic, copy, nullable) void(^zf_playerDisappearingInScrollView)(NSIndexPath *indexPath, CGFloat playerDisapperaPercent);
  90. /// The block invoked When the player will appeared.
  91. @property (nonatomic, copy, nullable) void(^zf_playerWillAppearInScrollView)(NSIndexPath *indexPath);
  92. /// The block invoked When the player did appeared.
  93. @property (nonatomic, copy, nullable) void(^zf_playerDidAppearInScrollView)(NSIndexPath *indexPath);
  94. /// The block invoked When the player will disappear.
  95. @property (nonatomic, copy, nullable) void(^zf_playerWillDisappearInScrollView)(NSIndexPath *indexPath);
  96. /// The block invoked When the player did disappeared.
  97. @property (nonatomic, copy, nullable) void(^zf_playerDidDisappearInScrollView)(NSIndexPath *indexPath);
  98. /// The block invoked When the player did stop scroll.
  99. @property (nonatomic, copy, nullable) void(^zf_scrollViewDidEndScrollingCallback)(NSIndexPath *indexPath);
  100. /// The block invoked When the player did scroll.
  101. @property (nonatomic, copy, nullable) void(^zf_scrollViewDidScrollCallback)(NSIndexPath *indexPath);
  102. /// The block invoked When the player should play.
  103. @property (nonatomic, copy, nullable) void(^zf_playerShouldPlayInScrollView)(NSIndexPath *indexPath);
  104. /// The current player scroll slides off the screen percent.
  105. /// the property used when the `stopWhileNotVisible` is YES, stop the current playing player.
  106. /// the property used when the `stopWhileNotVisible` is NO, the current playing player add to small container view.
  107. /// 0.0~1.0, defalut is 0.5.
  108. /// 0.0 is the player will disappear.
  109. /// 1.0 is the player did disappear.
  110. @property (nonatomic) CGFloat zf_playerDisapperaPercent;
  111. /// The current player scroll to the screen percent to play the video.
  112. /// 0.0~1.0, defalut is 0.0.
  113. /// 0.0 is the player will appear.
  114. /// 1.0 is the player did appear.
  115. @property (nonatomic) CGFloat zf_playerApperaPercent;
  116. /// The current player controller is disappear, not dealloc
  117. @property (nonatomic) BOOL zf_viewControllerDisappear;
  118. /// Has stopped playing
  119. @property (nonatomic, assign) BOOL zf_stopPlay;
  120. /// The currently playing cell stop playing when the cell has out off the screen,defalut is YES.
  121. @property (nonatomic, assign) BOOL zf_stopWhileNotVisible;
  122. /// The indexPath is playing.
  123. @property (nonatomic, nullable) NSIndexPath *zf_playingIndexPath;
  124. /// The indexPath should be play while scrolling.
  125. @property (nonatomic, nullable) NSIndexPath *zf_shouldPlayIndexPath;
  126. /// WWANA networks play automatically,default NO.
  127. @property (nonatomic, getter=zf_isWWANAutoPlay) BOOL zf_WWANAutoPlay;
  128. /// The player should auto player,default is YES.
  129. @property (nonatomic) BOOL zf_shouldAutoPlay;
  130. /// The view tag that the player display in scrollView.
  131. @property (nonatomic) NSInteger zf_containerViewTag;
  132. /// The video contrainerView in normal model.
  133. @property (nonatomic, strong) UIView *zf_containerView;
  134. /// The video contrainerView type.
  135. @property (nonatomic, assign) ZFPlayerContainerType zf_containerType;
  136. /// Filter the cell that should be played when the scroll is stopped (to play when the scroll is stopped).
  137. - (void)zf_filterShouldPlayCellWhileScrolled:(void (^ __nullable)(NSIndexPath *indexPath))handler;
  138. /// Filter the cell that should be played while scrolling (you can use this to filter the highlighted cell).
  139. - (void)zf_filterShouldPlayCellWhileScrolling:(void (^ __nullable)(NSIndexPath *indexPath))handler;
  140. @end
  141. @interface UIScrollView (ZFPlayerDeprecated)
  142. /// The block invoked When the player did stop scroll.
  143. @property (nonatomic, copy, nullable) void(^zf_scrollViewDidStopScrollCallback)(NSIndexPath *indexPath) __attribute__((deprecated("use `ZFPlayerController.zf_scrollViewDidEndScrollingCallback` instead.")));
  144. /// The block invoked When the player should play.
  145. @property (nonatomic, copy, nullable) void(^zf_shouldPlayIndexPathCallback)(NSIndexPath *indexPath) __attribute__((deprecated("use `ZFPlayerController.zf_playerShouldPlayInScrollView` instead.")));
  146. @end
  147. NS_ASSUME_NONNULL_END