// // ZFScrollViewViewController.m // ZFPlayer_Example // // Created by 紫枫 on 2019/6/5. // Copyright © 2019 紫枫. All rights reserved. // #import "ZFScrollViewViewController.h" #import #import #import #import #import #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 () @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