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;
  
}

你可能感兴趣的:(iOS设置只支持某个界面横屏)