需求: 因为其分别要的是 H5, 拓客, 和阿里云的界面, 现在我需要在三个类设置横竖屏
HKMainViewController // 只支持竖屏
HKTKPlayerViewController //只支持横屏
HKPlayerViewController //横竖屏都支持
0.首先在工程的 General 里设置
image.png1.首先在 AppDelegate.h里添加如下代码
//0所有 //1竖 //2横
@property (nonatomic,assign) NSUInteger allowRotation;
2.首先在 AppDelegate.m里添加如下代码
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.allowRotation == 0) { //当允许时,支持所有方向
return UIInterfaceOrientationMaskAll;
}else if (self.allowRotation == 1) {//当允许时,支持竖屏
return UIInterfaceOrientationMaskPortrait;
}else //当允许时,支持横屏幕
return UIInterfaceOrientationMaskLandscapeRight;
}
3.设置某个类支持的横竖屏
3.1.HKMainViewController支持竖屏
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = 1;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = 0;
}
3.2HKTKPlayerViewController支持横屏
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = 2;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = 0;
}
3.3HKPlayerViewController支持横竖屏
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = 0;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = 0;
}
网友评论