2016-11-27 72 views
0

我正在設計一個通用應用程序,我喜歡僅支持iPhone和iPad的肖像。但我需要iPad來支持經常和顛倒的縱向。如何在縱向模式下支持iPad的180度變體?

爲iPhone和iPad在info.plistPortrait (top home button)Portrait (bottom home button).

AppDeleagte.swift

var shouldSupportAllOrientation = false 

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { 
    if (shouldSupportAllOrientation == true){ 
     return UIInterfaceOrientationMask.all 
    } 
    return UIInterfaceOrientationMask.portrait 
} 

所以我組支持的接口方位ViewController.swift

override func viewWillAppear(_ animated: Bool) { 
     let appdelegate = UIApplication.shared.delegate as! AppDelegate 
     appdelegate.shouldSupportAllOrientation = false 

    let value = UIInterfaceOrientation.portraitUpsideDown.rawValue 
    UIDevice.current.setValue(value, forKey: "orientation") 
} 

繼當我轉動我的iPad在模擬器中顛倒過來,它仍然是upsi減少並且不旋轉180度。我哪裏錯了?

回答

0

我能夠做

繼實現這一目標的方向在AppDeleagte.swift

var shouldSupportAllOrientation = false 

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { 
    if (shouldSupportAllOrientation == true){ 
     return UIInterfaceOrientationMask.all 
    } 
    return [UIInterfaceOrientationMask.portrait, UIInterfaceOrientationMask.portraitUpsideDown] 
} 

繼ViewController.swift

override func viewWillAppear(_ animated: Bool) { 
     let appdelegate = UIApplication.shared.delegate as! AppDelegate 
     appdelegate.shouldSupportAllOrientation = false 
} 
0

您沒有提到您爲項目配置了部署信息的方式。默認情況下,「倒掛」選項選中通用的項目,你需要選擇它來獲取你需要

Xcode Deployment Info

+0

我沒有檢查倒置,但它仍然無法正常工作。 – Coder221

相關問題