ZFRotationViewController.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // ZFRotationViewController.m
  3. // ZFPlayer_Example
  4. //
  5. // Created by 紫枫 on 2019/6/4.
  6. // Copyright © 2019 紫枫. All rights reserved.
  7. //
  8. #import "ZFRotationViewController.h"
  9. #import <ZFPlayer/ZFAVPlayerManager.h>
  10. #import <ZFPlayer/ZFPlayerControlView.h>
  11. #import <ZFPlayer/ZFIJKPlayerManager.h>
  12. #import <ZFPlayer/UIView+ZFFrame.h>
  13. #import <ZFPlayer/ZFPlayerConst.h>
  14. @interface ZFRotationViewController ()
  15. @property (nonatomic, strong) ZFPlayerController *player;
  16. @property (nonatomic, strong) UIView *containerView;
  17. @property (nonatomic, strong) ZFPlayerControlView *controlView;
  18. @end
  19. @implementation ZFRotationViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.view.backgroundColor = [UIColor whiteColor];
  23. [self.view addSubview:self.containerView];
  24. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  25. /// 播放器相关
  26. self.player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:self.containerView];
  27. self.player.controlView = self.controlView;
  28. playerManager.assetURL = [NSURL URLWithString:@"https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-tpl-cc-us-20170912_1280x720h.mp4"];
  29. [self.controlView showTitle:@"视频标题" coverURLString:@"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" fullScreenMode:ZFFullScreenModeLandscape];
  30. }
  31. - (void)viewWillLayoutSubviews {
  32. [super viewWillLayoutSubviews];
  33. CGFloat x = 0;
  34. CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  35. CGFloat w = CGRectGetWidth(self.view.frame);
  36. CGFloat h = w*9/16;
  37. self.containerView.frame = CGRectMake(x, y, w, h);
  38. }
  39. - (UIStatusBarStyle)preferredStatusBarStyle {
  40. return UIStatusBarStyleDefault;
  41. }
  42. - (BOOL)prefersStatusBarHidden {
  43. return NO;
  44. }
  45. - (BOOL)shouldAutorotate {
  46. return NO;
  47. }
  48. - (IBAction)landscapeClick {
  49. self.controlView.fullScreenMode = ZFFullScreenModeLandscape;
  50. [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:YES completion:nil];
  51. }
  52. - (IBAction)portraitClick {
  53. self.controlView.fullScreenMode = ZFFullScreenModePortrait;
  54. [self.player enterPortraitFullScreen:YES animated:YES];
  55. }
  56. #pragma mark - about keyboard orientation
  57. /// 键盘支持横屏,这里必须设置支持多个方向
  58. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  59. return UIInterfaceOrientationMaskPortrait;
  60. }
  61. - (ZFPlayerControlView *)controlView {
  62. if (!_controlView) {
  63. _controlView = [ZFPlayerControlView new];
  64. }
  65. return _controlView;
  66. }
  67. - (UIView *)containerView {
  68. if (!_containerView) {
  69. _containerView = [UIView new];
  70. }
  71. return _containerView;
  72. }
  73. @end