2017-08-24 8 views
0

iOSアプリケーションで作業しています。すべてのViewControllerはポートレートとランドスケープの両方をサポートするViewControllerを除き、ポートレートの向きのみをサポートします。私はそのViewControllerのこのコードを試してくださいiOSの特定のビューコントローラのランドスケープとポートレートのデバイスの向きをサポートする3

override var shouldAutorotate: Bool { 
    return false 
} 

override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 
    return .landscapeLeft 
} 

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 
    return .landscapeLeft 
} 

しかし、これはうまくいかなかった、いずれかを助けることができますか? おかげAppDelegateで

答えて

0

は、それが作品だあなたのビューコントローラ

+0

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { if let navigationController = UIApplication.topViewController() { if navigationController is YOURVIEWCONTROLLERNAME { return UIInterfaceOrientationMask.all } else { return UIInterfaceOrientationMask.portrait } } return UIInterfaceOrientationMask.portrait } extension UIApplication { class func topViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? { if let nav = base as? UINavigationController { return topViewController(base: nav.visibleViewController) } if let tab = base as? UITabBarController { if let selected = tab.selectedViewController { return topViewController(base: selected) } } if let presented = base?.presentedViewController { return topViewController(base: presented) } return base } 

変更YOURVIEWCONTROLLERNAMEを、このイベントを追加し、非常に多くの人に感謝 – DevMhd

関連する問題