RQNewFeatureViewController.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // RQNewFeatureViewController.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/23.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQNewFeatureViewController.h"
  9. #import "AppDelegate.h"
  10. #import <ZFPlayer/ZFAVPlayerManager.h>
  11. @interface RQNewFeatureViewController () <UIScrollViewDelegate>
  12. /// 滚动视图
  13. @property (nonatomic, readwrite, strong) UIScrollView *scrollView;
  14. /// 分页控件
  15. @property (nonatomic, readwrite, strong) UIPageControl *pageControl;
  16. /// 开始按钮
  17. @property (nonatomic, readwrite, strong) UIButton *startButton;
  18. /// viewModel
  19. @property (nonatomic, readwrite, strong) RQNewFeatureViewModel *viewModel;
  20. @property (nonatomic, readwrite, strong) ZFPlayerController *player;
  21. @property (nonatomic, readwrite, strong) ZFPlayerControlView *controlView;
  22. @end
  23. @implementation RQNewFeatureViewController
  24. @dynamic viewModel;
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self videoUI];
  28. }
  29. - (BOOL)shouldAutorotate {
  30. return NO;
  31. }
  32. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  33. return UIInterfaceOrientationMaskPortrait;
  34. }
  35. //
  36. //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  37. // return UIInterfaceOrientationLandscapeRight;
  38. //}
  39. - (void)viewWillAppear:(BOOL)animated {
  40. [super viewWillAppear:animated];
  41. self.player.viewControllerDisappear = NO;
  42. }
  43. - (void)viewWillDisappear:(BOOL)animated {
  44. [super viewWillDisappear:animated];
  45. self.player.viewControllerDisappear = YES;
  46. }
  47. #pragma mark - 监听方法
  48. /// 点击开始按钮
  49. - (void)clickStartButton {
  50. [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}];
  51. }
  52. #pragma mark - UIScrollViewDelegate
  53. /// UIScrollView 停止滚动
  54. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  55. // 当前页数
  56. self.pageControl.currentPage = scrollView.contentOffset.x / scrollView.bounds.size.width;
  57. }
  58. #pragma mark - 设置界面
  59. - (void)videoUI {
  60. NSURL *videoUrl = [[NSBundle mainBundle] URLForResource:self.viewModel.videoNameStr withExtension:@"mp4"];
  61. // if (videoUrl) {
  62. // self.zfPlayer = [[ZFPlayerController alloc] initWithPlayerManager:[[ZFAVPlayerManager alloc] init] containerView:self.view];
  63. // self.zfPlayer.controlView = self.controlView;
  64. // [self.zfPlayer setExitFullScreenWhenStop:YES];
  65. // [self.zfPlayer enterFullScreen:[self.viewModel.videoNameStr containsString:@"quanzhou"] animated:NO];
  66. // self.zfPlayer.assetURLs = @[videoUrl];
  67. // [self.zfPlayer playTheIndex:0];
  68. // /// 播放完成
  69. // self.zfPlayer.playerDidToEnd = ^(id _Nonnull asset) {
  70. // @strongify(self)
  71. // if ([self.viewModel.videoNameStr containsString:@"quanzhou"]) {
  72. // RQ_COMMON_MANAGER.quanZhouLookVideoCount = 0;
  73. // }
  74. // [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}];
  75. // };
  76. // }
  77. @weakify(self)
  78. self.controlView.backBtnClickCallback = ^{
  79. };
  80. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  81. /// 播放器相关
  82. self.player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:self.view];
  83. self.player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionAll;
  84. if ([self.viewModel.videoNameStr containsString:@"quanzhou"]) {
  85. self.player.controlView = self.controlView;
  86. self.player.allowOrentitaionRotation = NO;
  87. self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskLandscape;
  88. /// 设置转屏方向
  89. [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:YES completion:^{
  90. @strongify(self)
  91. self.player.allowOrentitaionRotation = YES;
  92. }];
  93. }
  94. playerManager.assetURL = videoUrl;
  95. self.player.playerDidToEnd = ^(id<ZFPlayerMediaPlayback> _Nonnull asset) {
  96. @strongify(self)
  97. if ([self.viewModel.videoNameStr containsString:@"quanzhou"]) {
  98. RQ_COMMON_MANAGER.isQzLook = YES;
  99. self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskPortrait;
  100. [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:YES completion:^{
  101. [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}];
  102. }];
  103. } else {
  104. [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}];
  105. }
  106. };
  107. [self.player playTheIndex:0];
  108. }
  109. - (void)setupUI {
  110. [self _prepareScrollView];
  111. [self _preparePageControl];
  112. [self _prepareLastPage];
  113. }
  114. /// 准备最后一页控件
  115. - (void)_prepareLastPage {
  116. @weakify(self)
  117. UIImageView *imageView = self.scrollView.subviews.lastObject;
  118. imageView.userInteractionEnabled = YES;
  119. [imageView addSubview:self.startButton];
  120. [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
  121. @strongify(self)
  122. make.top.mas_equalTo(imageView.mas_top).mas_offset(16 + RQ_APPLICATION_STATUS_BAR_HEIGHT);
  123. make.right.mas_equalTo(imageView.mas_right).mas_offset(-16);
  124. make.size.mas_equalTo(CGSizeMake(54, 27));
  125. self.startButton.layer.cornerRadius = 13.5;
  126. }];
  127. }
  128. /// 准备分页控件
  129. - (void)_preparePageControl {
  130. @weakify(self)
  131. [self.view addSubview:self.pageControl];
  132. self.pageControl.numberOfPages = 4;
  133. self.pageControl.currentPage = 0;
  134. [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
  135. @strongify(self)
  136. make.centerX.equalTo(self.view);
  137. make.bottom.equalTo(self.view).offset(-(40));
  138. }];
  139. }
  140. /// 准备 UIScrollView
  141. - (void)_prepareScrollView {
  142. [self.view addSubview:self.scrollView];
  143. self.scrollView.frame = self.view.bounds;
  144. // 添加图像视图
  145. for (int i = 0; i < 4; ++i) {
  146. UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"welcom_page_%d", i + 1]];
  147. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  148. // 设置大小
  149. imageView.frame = CGRectOffset(self.view.bounds, i * self.view.bounds.size.width, 0);
  150. [self.scrollView addSubview:imageView];
  151. }
  152. // 设置 contentSize
  153. self.scrollView.contentSize = CGRectInset(self.view.bounds, -1.5 * self.view.bounds.size.width, 0).size;
  154. /// 适配 iOS11
  155. RQAdjustsScrollViewInsets_Never(self.scrollView);
  156. }
  157. #pragma mark - 懒加载控件
  158. - (UIScrollView *)scrollView {
  159. if (_scrollView == nil) {
  160. _scrollView = [[UIScrollView alloc] init];
  161. _scrollView.showsHorizontalScrollIndicator = NO;
  162. _scrollView.showsVerticalScrollIndicator = NO;
  163. _scrollView.bounces = NO;
  164. _scrollView.pagingEnabled = YES;
  165. _scrollView.delegate = self;
  166. }
  167. return _scrollView;
  168. }
  169. - (UIPageControl *)pageControl {
  170. if (_pageControl == nil) {
  171. _pageControl = [[UIPageControl alloc] init];
  172. _pageControl.pageIndicatorTintColor = [UIColor blackColor];
  173. _pageControl.currentPageIndicatorTintColor = RQ_MAIN_COLOR;
  174. // 提示:需要禁止用户交互,否则用户点击小圆点,会移动,但是页面不会变化
  175. _pageControl.userInteractionEnabled = NO;
  176. }
  177. return _pageControl;
  178. }
  179. - (UIButton *)startButton {
  180. if (_startButton == nil) {
  181. _startButton = [UIButton buttonWithType:UIButtonTypeCustom];
  182. [_startButton setTitle:@" 跳 过 " forState:UIControlStateNormal];
  183. [_startButton addTarget:self action:@selector(clickStartButton) forControlEvents:UIControlEventTouchUpInside];
  184. _startButton.titleLabel.font = RQRegularFont(13);
  185. _startButton.clipsToBounds = YES;
  186. [_startButton setBackgroundColor:[UIColor colorWithWhite:0.1 alpha:0.3]];
  187. }
  188. return _startButton;
  189. }
  190. - (ZFPlayerControlView *)controlView {
  191. if (!_controlView) {
  192. _controlView = [ZFPlayerControlView new];
  193. _controlView.fastViewAnimated = YES;
  194. _controlView.effectViewShow = NO;
  195. _controlView.prepareShowLoading = YES;
  196. _controlView.showCustomStatusBar = YES;
  197. _controlView.landScapeControlView.titleLabel.text = @"报名学车注意事项";
  198. _controlView.landScapeControlView.backBtn.hidden = YES;
  199. _controlView.landScapeControlView.lockBtn.hidden = YES;
  200. _controlView.landScapeControlView.playOrPauseBtn.hidden = YES;
  201. _controlView.customDisablePanMovingDirection = YES;
  202. _controlView.landScapeControlView.slider.userInteractionEnabled = NO;
  203. }
  204. return _controlView;
  205. }
  206. @end