单个ViewController支持横屏,其他全竖屏

1.首先需要Xcode中选中支持的屏幕方向

2. 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;

}

 

3 在需要支持横竖屏的controller中:

viewWillApplear 中

//在视图出现的时候,将allowRotate改为1,

AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

delegate.allowRotate = 1;

 

viewWillDisappear中

//在视图出现的时候,将allowRotate改为0,
AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.allowRotate = 0;

 

 

参考链接:

https://blog.csdn.net/SandyLoo/article/details/52044190?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~first_rank_v2~rank_v25-2-52044190.nonecase&utm_term=ios%20所有页面都是竖屏

https://www.jianshu.com/p/f938a712d93c?nomobile

posted on 2016-06-23 14:02  🌞Bob  阅读(212)  评论(0编辑  收藏  举报

导航