ZFScrollViewViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // ZFScrollViewViewController.m
  3. // ZFPlayer_Example
  4. //
  5. // Created by 紫枫 on 2019/6/5.
  6. // Copyright © 2019 紫枫. All rights reserved.
  7. //
  8. #import "ZFScrollViewViewController.h"
  9. #import <ZFPlayer/ZFAVPlayerManager.h>
  10. #import <ZFPlayer/ZFPlayerControlView.h>
  11. #import <ZFPlayer/ZFIJKPlayerManager.h>
  12. #import <ZFPlayer/UIView+ZFFrame.h>
  13. #import <ZFPlayer/ZFPlayerConst.h>
  14. #import "UIImageView+ZFCache.h"
  15. #import "ZFUtilities.h"
  16. static NSString *kVideoCover = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
  17. @interface ZFScrollViewViewController () <UIScrollViewDelegate>
  18. @property (nonatomic, strong) UIScrollView *scrollView;
  19. @property (nonatomic, strong) ZFPlayerController *player;
  20. @property (nonatomic, strong) UIImageView *containerView;
  21. @property (nonatomic, strong) ZFPlayerControlView *controlView;
  22. @property (nonatomic, strong) UIButton *playBtn;
  23. @end
  24. @implementation ZFScrollViewViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.view.backgroundColor = [UIColor whiteColor];
  28. [self.view addSubview:self.scrollView];
  29. self.scrollView.frame = self.view.bounds;
  30. [self.scrollView addSubview:self.containerView];
  31. [self.containerView addSubview:self.playBtn];
  32. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  33. /// 播放器相关
  34. self.player = [[ZFPlayerController alloc] initWithScrollView:self.scrollView playerManager:playerManager containerView:self.containerView];
  35. self.player.controlView = self.controlView;
  36. self.player.playerDisapperaPercent = 1.0;
  37. self.player.playerApperaPercent = 0.0;
  38. /// 播放小窗相关
  39. self.player.stopWhileNotVisible = NO;
  40. self.player.shouldAutoPlay = NO;
  41. CGFloat margin = 20;
  42. CGFloat w = ZFPlayer_ScreenWidth/2;
  43. CGFloat h = w * 9/16;
  44. CGFloat x = ZFPlayer_ScreenWidth - w - margin;
  45. CGFloat y = ZFPlayer_ScreenHeight - h - margin;
  46. self.player.smallFloatView.frame = CGRectMake(x, y, w, h);
  47. self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 3000);
  48. }
  49. - (void)viewWillLayoutSubviews {
  50. [super viewWillLayoutSubviews];
  51. CGFloat x = 0;
  52. CGFloat y = 900;
  53. CGFloat w = CGRectGetWidth(self.view.frame);
  54. CGFloat h = w*9/16;
  55. self.containerView.frame = CGRectMake(x, y, w, h);
  56. w = 44;
  57. h = w;
  58. x = (CGRectGetWidth(self.containerView.frame)-w)/2;
  59. y = (CGRectGetHeight(self.containerView.frame)-h)/2;
  60. self.playBtn.frame = CGRectMake(x, y, w, h);
  61. }
  62. - (UIStatusBarStyle)preferredStatusBarStyle {
  63. return UIStatusBarStyleDefault;
  64. }
  65. - (BOOL)prefersStatusBarHidden {
  66. return NO;
  67. }
  68. - (BOOL)shouldAutorotate {
  69. return NO;
  70. }
  71. #pragma mark - action
  72. - (void)playClick:(UIButton *)sender {
  73. self.player.currentPlayerManager.assetURL = [NSURL URLWithString:@"https://www.apple.com/105/media/cn/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/bruce/mac-bruce-tpl-cn-2018_1280x720h.mp4"];
  74. [self.controlView showTitle:@"UIScrollView播放" coverURLString:@"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" fullScreenMode:ZFFullScreenModeAutomatic];
  75. }
  76. #pragma mark - UIScrollViewDelegate
  77. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  78. [scrollView zf_scrollViewDidEndDecelerating];
  79. }
  80. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
  81. [scrollView zf_scrollViewDidEndDraggingWillDecelerate:decelerate];
  82. }
  83. - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
  84. [scrollView zf_scrollViewDidScrollToTop];
  85. }
  86. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  87. [scrollView zf_scrollViewDidScroll];
  88. }
  89. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  90. [scrollView zf_scrollViewWillBeginDragging];
  91. }
  92. #pragma mark - about keyboard orientation
  93. /// 键盘支持横屏,这里必须设置支持多个方向
  94. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  95. return UIInterfaceOrientationMaskPortrait;
  96. }
  97. - (ZFPlayerControlView *)controlView {
  98. if (!_controlView) {
  99. _controlView = [ZFPlayerControlView new];
  100. _controlView.prepareShowLoading = YES;
  101. }
  102. return _controlView;
  103. }
  104. - (UIImageView *)containerView {
  105. if (!_containerView) {
  106. _containerView = [UIImageView new];
  107. [_containerView setImageWithURLString:kVideoCover placeholder:nil];
  108. }
  109. return _containerView;
  110. }
  111. - (UIButton *)playBtn {
  112. if (!_playBtn) {
  113. _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  114. [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
  115. [_playBtn addTarget:self action:@selector(playClick:) forControlEvents:UIControlEventTouchUpInside];
  116. }
  117. return _playBtn;
  118. }
  119. - (UIScrollView *)scrollView {
  120. if (!_scrollView) {
  121. _scrollView = [[UIScrollView alloc] init];
  122. _scrollView.delegate = self;
  123. }
  124. return _scrollView;
  125. }
  126. @end