iOS 大部分页面竖屏显示,个别页面横屏显示

我将横屏显示的controller显示了statusBar将将背景色显示成透明
效果如下图
效果显示

Demo下载

在AppDelegate中添加需要横屏显示的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* 横竖屏幕切换
* NaviViewController为我设置的根控制器
* controller需要横屏显示的控制器
*/
- (UIInterfaceOrientationMask)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(UIWindow *)window {
__block UIInterfaceOrientationMask mask = 0;
for (UIWindow *subWindow in [UIApplication sharedApplication].windows) {
// NaviViewController为我设置的根控制器
if ([subWindow.rootViewController
isKindOfClass:NSClassFromString(@"NaviViewController")]) {
NSArray *arrays = [subWindow.rootViewController childViewControllers];
[arrays enumerateObjectsUsingBlock:^(
UIViewController *obj, NSUInteger idx, BOOL *_Nonnull stop) {
//需要横屏显示的controller
if ([obj isKindOfClass:NSClassFromString(@"ViewController11")]) {
mask = UIInterfaceOrientationMaskAll;
return;
} else {
mask = UIInterfaceOrientationMaskPortrait;
return;
}
}];
}
}
return mask;
}

需要横屏或旋转显示的页面

1
2
3
4
5
6
7
/**
* 使用此句代码,会调用delegate里面的supportedInterfaceOrientationsForWindow方法
* 默认显示numberWithInteger后的类型
*/
[[UIDevice currentDevice]
setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeRight]
forKey:@"orientation"];