美文网首页
iOS横竖屏 Appdelegate设置

iOS横竖屏 Appdelegate设置

作者: 9d8c8692519b | 来源:发表于2018-12-27 12:30 被阅读10次
    除个别控制器外,全局页面竖屏显示
    #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;
    }
    

    相关文章

      网友评论

          本文标题:iOS横竖屏 Appdelegate设置

          本文链接:https://www.haomeiwen.com/subject/sxjrlqtx.html