2017-10-28 71 views
0

我怎麼能只在IPhone鎖定方向上IPhone

檢測設備鎖定方向是iPhone

if UIDevice().userInterfaceIdiom == .phone { 
    switch UIScreen.main.nativeBounds.height { 
    case 1136: 
     print("iPhone 5,5S,5C") 
    case 1334: 
     print("iPhone 6,6S,7,8") 
    case 2208: 
     print("iPhone 6+,6S+,7+,8+") 
    case 2436: 
     print("iPhone X") 
    default: 
     print("unknown") 
    } 
} 

我用這個代碼,但他是在iPhone和iPad上的

鎖定方向

In ViewDidLoad:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { 
       return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue) 
} 

回答

1

你可以簡單地設置在info.plist

也許這回答你的問題? https://stackoverflow.com/a/30537068/8364981

+0

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/ review/low-quality-posts/17766492) –

+0

感謝您的回覆。引用的答案包括截圖。我會被允許複製嗎? –