ZFKeyboardViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // ZFKeyboardViewController.m
  3. // ZFPlayer_Example
  4. //
  5. // Created by 紫枫 on 2018/5/25.
  6. // Copyright © 2018年 紫枫. All rights reserved.
  7. //
  8. #import "ZFKeyboardViewController.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 ZFKeyboardViewController ()
  15. @property (nonatomic, strong) ZFPlayerController *player;
  16. @property (nonatomic, strong) UIView *containerView;
  17. @property (nonatomic, strong) ZFPlayerControlView *controlView;
  18. @property (nonatomic, strong) UITextField *textField;
  19. @end
  20. @implementation ZFKeyboardViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. [self.view addSubview:self.containerView];
  25. [self.controlView addSubview:self.textField];
  26. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  27. /// 播放器相关
  28. self.player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:self.containerView];
  29. self.player.controlView = self.controlView;
  30. @zf_weakify(self)
  31. self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
  32. @zf_strongify(self)
  33. [self.textField resignFirstResponder];
  34. };
  35. self.player.orientationDidChanged = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
  36. @zf_strongify(self)
  37. [self updateTextFieldLayout];
  38. };
  39. NSString *URLString = [@"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" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  40. playerManager.assetURL = [NSURL URLWithString:URLString];
  41. [self.controlView showTitle:@"视频标题" coverURLString:@"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" fullScreenMode:ZFFullScreenModeLandscape];
  42. [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  43. }
  44. - (void)keyboardWillShow:(NSNotification *)notification {
  45. CGRect frame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  46. NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  47. if (self.player.isFullScreen) {
  48. [UIView animateWithDuration:duration animations:^{
  49. self.textField.zf_bottom = self.controlView.zf_height - CGRectGetHeight(frame);
  50. }];
  51. }
  52. }
  53. - (void)viewWillLayoutSubviews {
  54. [super viewWillLayoutSubviews];
  55. CGFloat x = 0;
  56. CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  57. CGFloat w = CGRectGetWidth(self.view.frame);
  58. CGFloat h = w*9/16;
  59. self.containerView.frame = CGRectMake(x, y, w, h);
  60. [self updateTextFieldLayout];
  61. }
  62. - (void)updateTextFieldLayout {
  63. CGFloat w = 200;
  64. CGFloat h = 35;
  65. CGFloat x = (self.controlView.zf_width - w)/2;
  66. CGFloat y = self.controlView.zf_height - h - 60;
  67. self.textField.frame = CGRectMake(x, y, w, h);
  68. }
  69. - (UIStatusBarStyle)preferredStatusBarStyle {
  70. return UIStatusBarStyleDefault;
  71. }
  72. - (BOOL)prefersStatusBarHidden {
  73. return NO;
  74. }
  75. - (BOOL)shouldAutorotate {
  76. return NO;
  77. }
  78. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  79. [self.textField resignFirstResponder];
  80. }
  81. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  82. return UIInterfaceOrientationMaskPortrait;
  83. }
  84. - (ZFPlayerControlView *)controlView {
  85. if (!_controlView) {
  86. _controlView = [ZFPlayerControlView new];
  87. _controlView.prepareShowControlView = YES;
  88. _controlView.prepareShowLoading = YES;
  89. }
  90. return _controlView;
  91. }
  92. - (UITextField *)textField {
  93. if (!_textField) {
  94. _textField = [[UITextField alloc] init];
  95. _textField.backgroundColor = [UIColor whiteColor];
  96. _textField.placeholder = @"Click on the input";
  97. }
  98. return _textField;
  99. }
  100. - (UIView *)containerView {
  101. if (!_containerView) {
  102. _containerView = [UIView new];
  103. }
  104. return _containerView;
  105. }
  106. @end