iOS设置只支持某个界面横屏

iOS设置只支持某个界面横屏

注意:首先Device Orientation哪里只勾选:Portrait,其他的都不要勾选。

一、指定某个界面横屏

AppDelegate.h
@property (nonatomic,assign)NSInteger allowRotate; 


AppDelegate.m

//此方法会在设备横竖屏变化的时候调用
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    
    //   NSLog(@"方向  =============   %ld", _allowRotate);
    if (_allowRotate == 1) {
        return UIInterfaceOrientationMaskAll;
    }else{
        return (UIInterfaceOrientationMaskPortrait);
    }
}


// 返回是否支持设备自动旋转
- (BOOL)shouldAutorotate
{
    if (_allowRotate == 1) {
        return YES;
    }
    return NO;
}

二、基类

//将要出现
-(void)viewWillAppear:(BOOL)animated{
//设置成竖屏
    AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    delegate.allowRotate = 0;
}

三、要竖屏的控制器里这样写

//将要出现
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//设置成支持横屏
    AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    delegate.allowRotate = 1;
  
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容