我无法为单个屏幕旋转我的肖像应用程序

时间:2018-02-15 07:18:42

标签: ios swift xcode uinavigationcontroller screen-rotation

enter image description here

这是我的故事板的一部分,我试过但我无法处理它。

我在navigationController中尝试了什么,它没有用。你有什么建议吗?

override var shouldAutorotate : Bool {
    if self.topViewController != nil{
        return self.topViewController!.shouldAutorotate
    }else{
        return  super.shouldAutorotate
    }
}

override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
    if self.topViewController != nil{
        return self.topViewController!.supportedInterfaceOrientations
    }else{
        return  super.supportedInterfaceOrientations
    }
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
    if self.topViewController != nil{
        return self.topViewController!.preferredInterfaceOrientationForPresentation
    }else{
        return  super.preferredInterfaceOrientationForPresentation
    }
}

override var preferredStatusBarStyle : UIStatusBarStyle {
    return self.topViewController!.preferredStatusBarStyle
}

1 个答案:

答案 0 :(得分:0)

您可以将此应用生命周期方法 supportedInterfaceOrientationsFor 添加到您的应用委托类中,以根据您的要求支持各种方向。

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {

    if self.window?.rootViewController != nil {

        if self.window!.rootViewController! is UITabBarController {

            if self.window?.rootViewController?.childViewControllers.last is UINavigationController {

                if self.window?.rootViewController?.childViewControllers.last?.childViewControllers.last is YourViewController {
                    return UIInterfaceOrientationMask.all;
                } else {
                    return UIInterfaceOrientationMask.portrait;
                }

            } else {
                if self.window!.rootViewController?.childViewControllers.last is YourViewController {
                    return UIInterfaceOrientationMask.all;
                } else {
                    return UIInterfaceOrientationMask.portrait;
                }
            }                       
        }
    }
}