| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- //
- // ZFScrollViewViewController.m
- // ZFPlayer_Example
- //
- // Created by 紫枫 on 2019/6/5.
- // Copyright © 2019 紫枫. All rights reserved.
- //
- #import "ZFScrollViewViewController.h"
- #import <ZFPlayer/ZFAVPlayerManager.h>
- #import <ZFPlayer/ZFPlayerControlView.h>
- #import <ZFPlayer/ZFIJKPlayerManager.h>
- #import <ZFPlayer/UIView+ZFFrame.h>
- #import <ZFPlayer/ZFPlayerConst.h>
- #import "UIImageView+ZFCache.h"
- #import "ZFUtilities.h"
- static NSString *kVideoCover = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
- @interface ZFScrollViewViewController () <UIScrollViewDelegate>
- @property (nonatomic, strong) UIScrollView *scrollView;
- @property (nonatomic, strong) ZFPlayerController *player;
- @property (nonatomic, strong) UIImageView *containerView;
- @property (nonatomic, strong) ZFPlayerControlView *controlView;
- @property (nonatomic, strong) UIButton *playBtn;
- @end
- @implementation ZFScrollViewViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.scrollView];
- self.scrollView.frame = self.view.bounds;
- [self.scrollView addSubview:self.containerView];
- [self.containerView addSubview:self.playBtn];
-
- ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
-
- /// 播放器相关
- self.player = [[ZFPlayerController alloc] initWithScrollView:self.scrollView playerManager:playerManager containerView:self.containerView];
- self.player.controlView = self.controlView;
- self.player.playerDisapperaPercent = 1.0;
- self.player.playerApperaPercent = 0.0;
- /// 播放小窗相关
- self.player.stopWhileNotVisible = NO;
- self.player.shouldAutoPlay = NO;
-
- CGFloat margin = 20;
- CGFloat w = ZFPlayer_ScreenWidth/2;
- CGFloat h = w * 9/16;
- CGFloat x = ZFPlayer_ScreenWidth - w - margin;
- CGFloat y = ZFPlayer_ScreenHeight - h - margin;
- self.player.smallFloatView.frame = CGRectMake(x, y, w, h);
- self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 3000);
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
-
- CGFloat x = 0;
- CGFloat y = 900;
- CGFloat w = CGRectGetWidth(self.view.frame);
- CGFloat h = w*9/16;
- self.containerView.frame = CGRectMake(x, y, w, h);
-
- w = 44;
- h = w;
- x = (CGRectGetWidth(self.containerView.frame)-w)/2;
- y = (CGRectGetHeight(self.containerView.frame)-h)/2;
- self.playBtn.frame = CGRectMake(x, y, w, h);
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return UIStatusBarStyleDefault;
- }
- - (BOOL)prefersStatusBarHidden {
- return NO;
- }
- - (BOOL)shouldAutorotate {
- return NO;
- }
- #pragma mark - action
- - (void)playClick:(UIButton *)sender {
- 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"];
- [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];
- }
- #pragma mark - UIScrollViewDelegate
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- [scrollView zf_scrollViewDidEndDecelerating];
- }
- - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
- [scrollView zf_scrollViewDidEndDraggingWillDecelerate:decelerate];
- }
- - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
- [scrollView zf_scrollViewDidScrollToTop];
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- [scrollView zf_scrollViewDidScroll];
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- [scrollView zf_scrollViewWillBeginDragging];
- }
- #pragma mark - about keyboard orientation
- /// 键盘支持横屏,这里必须设置支持多个方向
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return UIInterfaceOrientationMaskPortrait;
- }
- - (ZFPlayerControlView *)controlView {
- if (!_controlView) {
- _controlView = [ZFPlayerControlView new];
- _controlView.prepareShowLoading = YES;
- }
- return _controlView;
- }
- - (UIImageView *)containerView {
- if (!_containerView) {
- _containerView = [UIImageView new];
- [_containerView setImageWithURLString:kVideoCover placeholder:nil];
- }
- return _containerView;
- }
- - (UIButton *)playBtn {
- if (!_playBtn) {
- _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
- [_playBtn addTarget:self action:@selector(playClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _playBtn;
- }
- - (UIScrollView *)scrollView {
- if (!_scrollView) {
- _scrollView = [[UIScrollView alloc] init];
- _scrollView.delegate = self;
- }
- return _scrollView;
- }
- @end
|