123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- //
- // RQNewFeatureViewController.m
- // RQCommon
- //
- // Created by 张嵘 on 2018/11/23.
- // Copyright © 2018 张嵘. All rights reserved.
- //
- #import "RQNewFeatureViewController.h"
- #import "AppDelegate.h"
- #import <ZFPlayer/ZFAVPlayerManager.h>
- @interface RQNewFeatureViewController () <UIScrollViewDelegate>
- /// 滚动视图
- @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<ZFPlayerMediaPlayback> _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
|