刚开始只需要一个简单的播放器,后来是需要一个能旋转的,添加弹幕的,还有各种进度,亮度,音量,视频质量等等control的播放器...
好...进阶吧
解决: 屏幕想怎么转就怎么转,还要只有播放器页面转,其他页面都不旋转,还能在旋转后输入文字.
ps: 第一次写的player里只是把view进行了旋转,这样子旋转过来的页面,在输入文字的时候你会发现!天啊,键盘怎么从这里出来.(因为你旋转的不是屏幕)
解决方法:
1.添加两个NavigationController (设置方法把viewcontroller装在navigationcontroller里才起作用,母鸡点解)
2.设置允许转屏的navigationcontroller: ->RotatNavigationController
#import "RotatNavigationController.h"
@interface RotatNavigationController ()
@end
@implementation RotatNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
}
#pragma mark - 设置控制允许自动转屏和允许的方向
- (BOOL)shouldAutorotate
{
return YES; //允许自动转屏
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//根据navigation最上一个controller的设置设定支持的方向
return [self.topViewController supportedInterfaceOrientations];
}
3.设置不用转屏的navigationcontroller:->NomalNavigationController
#import "NomalNavigationController.h"
@interface NomalNavigationController ()
@end
@implementation NomalNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
#pragma mark - 设置控制允许自动转屏和允许的方向
- (BOOL)shouldAutorotate
{
return NO; //不允许自动转屏
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//设置只允许竖直方向
return UIInterfaceOrientationMaskPortrait;
}
4.最后把需要旋转的播放器的controller设置为RotatNavigationController的rootcontroller打开,然后在播放器的controller设置支持旋转的方向:
//设置允许转屏的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll; //支持所有方向
}
//监控屏幕旋转(通过监控屏幕旋转改变player.layer)
[[NSNotificationCenter defaultCenter] addObserver:self selector:
@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
- (void)statusBarOrientationChange:(NSNotification *)notification{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight){ // home键靠右
[self.playerLayer setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
}else if (orientation == UIInterfaceOrientationLandscapeLeft){ // home键靠左
[self.playerLayer setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
}else if (orientation == UIInterfaceOrientationPortrait){ //home在下
[self.playerLayer setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
}else{ //home在上
[self.playerLayer setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
}
}
好啦! 这下想怎么转就怎么转,也不影响其他页面了. 键盘也正常弹出来了.
其中有一点很奇怪的是, 设置允许屏幕旋转相关的在navigationcontroller上才生效,直接设置在controller上无效...望指点一二...
Demo点我下载 需要的拿去看看