// // RQNewFeatureViewController.m // RQCommon // // Created by 张嵘 on 2018/11/23. // Copyright © 2018 张嵘. All rights reserved. // #import "RQNewFeatureViewController.h" #import "AppDelegate.h" #import @interface RQNewFeatureViewController () /// 滚动视图 @property (nonatomic, readwrite, strong) UIScrollView *scrollView; /// 分页控件 @property (nonatomic, readwrite, strong) UIPageControl *pageControl; /// 开始按钮 @property (nonatomic, readwrite, strong) UIButton *startButton; /// viewModel @property (nonatomic, readwrite, strong) RQNewFeatureViewModel *viewModel; @property (nonatomic, readwrite, strong) ZFPlayerController *player; @property (nonatomic, readwrite, strong) ZFPlayerControlView *controlView; @end @implementation RQNewFeatureViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; [self videoUI]; } - (BOOL)shouldAutorotate { return NO; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } // //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { // return UIInterfaceOrientationLandscapeRight; //} - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.player.viewControllerDisappear = NO; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.player.viewControllerDisappear = YES; } #pragma mark - 监听方法 /// 点击开始按钮 - (void)clickStartButton { [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}]; } #pragma mark - UIScrollViewDelegate /// UIScrollView 停止滚动 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { // 当前页数 self.pageControl.currentPage = scrollView.contentOffset.x / scrollView.bounds.size.width; } #pragma mark - 设置界面 - (void)videoUI { NSURL *videoUrl = [[NSBundle mainBundle] URLForResource:self.viewModel.videoNameStr withExtension:@"mp4"]; // if (videoUrl) { // self.zfPlayer = [[ZFPlayerController alloc] initWithPlayerManager:[[ZFAVPlayerManager alloc] init] containerView:self.view]; // self.zfPlayer.controlView = self.controlView; // [self.zfPlayer setExitFullScreenWhenStop:YES]; // [self.zfPlayer enterFullScreen:[self.viewModel.videoNameStr containsString:@"quanzhou"] animated:NO]; // self.zfPlayer.assetURLs = @[videoUrl]; // [self.zfPlayer playTheIndex:0]; // /// 播放完成 // self.zfPlayer.playerDidToEnd = ^(id _Nonnull asset) { // @strongify(self) // if ([self.viewModel.videoNameStr containsString:@"quanzhou"]) { // RQ_COMMON_MANAGER.quanZhouLookVideoCount = 0; // } // [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}]; // }; // } @weakify(self) self.controlView.backBtnClickCallback = ^{ }; ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init]; /// 播放器相关 self.player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:self.view]; self.player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionAll; if ([self.viewModel.videoNameStr containsString:@"quanzhou"]) { self.player.controlView = self.controlView; self.player.allowOrentitaionRotation = NO; self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskLandscape; /// 设置转屏方向 [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:YES completion:^{ @strongify(self) self.player.allowOrentitaionRotation = YES; }]; } playerManager.assetURL = videoUrl; self.player.playerDidToEnd = ^(id _Nonnull asset) { @strongify(self) if ([self.viewModel.videoNameStr containsString:@"quanzhou"]) { RQ_COMMON_MANAGER.isQzLook = YES; self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskPortrait; [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:YES completion:^{ [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}]; }]; } else { [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}]; } }; [self.player playTheIndex:0]; } - (void)setupUI { [self _prepareScrollView]; [self _preparePageControl]; [self _prepareLastPage]; } /// 准备最后一页控件 - (void)_prepareLastPage { @weakify(self) UIImageView *imageView = self.scrollView.subviews.lastObject; imageView.userInteractionEnabled = YES; [imageView addSubview:self.startButton]; [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) { @strongify(self) make.top.mas_equalTo(imageView.mas_top).mas_offset(16 + RQ_APPLICATION_STATUS_BAR_HEIGHT); make.right.mas_equalTo(imageView.mas_right).mas_offset(-16); make.size.mas_equalTo(CGSizeMake(54, 27)); self.startButton.layer.cornerRadius = 13.5; }]; } /// 准备分页控件 - (void)_preparePageControl { @weakify(self) [self.view addSubview:self.pageControl]; self.pageControl.numberOfPages = 4; self.pageControl.currentPage = 0; [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) { @strongify(self) make.centerX.equalTo(self.view); make.bottom.equalTo(self.view).offset(-(40)); }]; } /// 准备 UIScrollView - (void)_prepareScrollView { [self.view addSubview:self.scrollView]; self.scrollView.frame = self.view.bounds; // 添加图像视图 for (int i = 0; i < 4; ++i) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"welcom_page_%d", i + 1]]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; // 设置大小 imageView.frame = CGRectOffset(self.view.bounds, i * self.view.bounds.size.width, 0); [self.scrollView addSubview:imageView]; } // 设置 contentSize self.scrollView.contentSize = CGRectInset(self.view.bounds, -1.5 * self.view.bounds.size.width, 0).size; /// 适配 iOS11 RQAdjustsScrollViewInsets_Never(self.scrollView); } #pragma mark - 懒加载控件 - (UIScrollView *)scrollView { if (_scrollView == nil) { _scrollView = [[UIScrollView alloc] init]; _scrollView.showsHorizontalScrollIndicator = NO; _scrollView.showsVerticalScrollIndicator = NO; _scrollView.bounces = NO; _scrollView.pagingEnabled = YES; _scrollView.delegate = self; } return _scrollView; } - (UIPageControl *)pageControl { if (_pageControl == nil) { _pageControl = [[UIPageControl alloc] init]; _pageControl.pageIndicatorTintColor = [UIColor blackColor]; _pageControl.currentPageIndicatorTintColor = RQ_MAIN_COLOR; // 提示:需要禁止用户交互,否则用户点击小圆点,会移动,但是页面不会变化 _pageControl.userInteractionEnabled = NO; } return _pageControl; } - (UIButton *)startButton { if (_startButton == nil) { _startButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_startButton setTitle:@" 跳 过 " forState:UIControlStateNormal]; [_startButton addTarget:self action:@selector(clickStartButton) forControlEvents:UIControlEventTouchUpInside]; _startButton.titleLabel.font = RQRegularFont(13); _startButton.clipsToBounds = YES; [_startButton setBackgroundColor:[UIColor colorWithWhite:0.1 alpha:0.3]]; } return _startButton; } - (ZFPlayerControlView *)controlView { if (!_controlView) { _controlView = [ZFPlayerControlView new]; _controlView.fastViewAnimated = YES; _controlView.effectViewShow = NO; _controlView.prepareShowLoading = YES; _controlView.showCustomStatusBar = YES; _controlView.landScapeControlView.titleLabel.text = @"报名学车注意事项"; _controlView.landScapeControlView.backBtn.hidden = YES; _controlView.landScapeControlView.lockBtn.hidden = YES; _controlView.landScapeControlView.playOrPauseBtn.hidden = YES; _controlView.customDisablePanMovingDirection = YES; _controlView.landScapeControlView.slider.userInteractionEnabled = NO; } return _controlView; } @end