美文网首页
横竖屏切换

横竖屏切换

作者: i爱吃土豆的猫 | 来源:发表于2018-06-16 14:35 被阅读14次

需求: 因为其分别要的是 H5, 拓客, 和阿里云的界面, 现在我需要在三个类设置横竖屏

HKMainViewController // 只支持竖屏
HKTKPlayerViewController //只支持横屏
HKPlayerViewController //横竖屏都支持

0.首先在工程的 General 里设置

image.png

1.首先在 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;
}

相关文章

网友评论

      本文标题:横竖屏切换

      本文链接:https://www.haomeiwen.com/subject/dwfbeftx.html