0

How can I lock orientation only on IPhone

Detect the device is 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")
    }
}

I use this code but he is lock orientation on iPhone and on iPad

In ViewDidLoad:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
                return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253

1 Answers1

1

You can simply set this in info.plist

Perhaps this answers your question? https://stackoverflow.com/a/30537068/8364981

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/17766492) – Mohd Oct 28 '17 at 12:56
  • Thanks for your reply. The answer referenced includes a screenshot. Would I be allowed to copy that? – Laurens Artapps Oct 28 '17 at 13:04