除个别控制器外,全局页面竖屏显示
#pragma mark - 屏幕旋转相关
//获取Window当前显示的ViewController
- (UIViewController *)currentViewController {
//获得当前活动窗口的根视图
UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController;
while (1)
{
//根据不同的页面切换方式,逐步取得最上层的viewController
if ([vc isKindOfClass:[UITabBarController class]]) {
vc = ((UITabBarController*)vc).selectedViewController;
}
if ([vc isKindOfClass:[UINavigationController class]]) {
vc = ((UINavigationController*)vc).visibleViewController;
}
if (vc.presentedViewController) {
vc = vc.presentedViewController;
}else{
break;
}
}
return vc;
}
//- (BOOL)shouldAutorotate
//{
// return YES;
//}
#pragma mark - InterfaceOrientation //应用支持的方向
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[[self currentViewController] class] isEqual:NSClassFromString(@"PlayerViewController")]) {
PlayerViewController *vc = (PlayerViewController *)[self currentViewController];
if (!vc.isHalfScreen) {
return UIInterfaceOrientationMaskLandscape;
}
}
return UIInterfaceOrientationMaskPortrait;
}
网友评论