0

My entire app is portrait mode. However, one screen needs to be able to rotate to landscape (for playing video). I am able to enable all orientation rotations with no problem via @Jonathan Danek's answer.

In my AppDelegate I have:

static var orientationLock = UIInterfaceOrientationMask.portrait

and subsequently:

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

So to enable rotation for all orientations, I do the following as the video view-controller is presented:

AppDelegate.orientationLock = UIInterfaceOrientationMask.all
UINavigationController.attemptRotationToDeviceOrientation()

This works great ..the problem is when I try to change it back to only portrait mode.

I am trying this as the video view-controller is dismissed:

AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UINavigationController.attemptRotationToDeviceOrientation()

..but it does not trigger the above AppDelegate's supportedInterfaceOrientationsForWindow function if the video view-controller is currently rotated to Landscape. What's interesting is that it will trigger the function if the video view-controller is currently rotated to Portrait.

So I'm wondering how I can set my one view-controller to have all orientations, but then change it back to just portrait?

Asperi
  • 228,894
  • 20
  • 464
  • 690
vikzilla
  • 3,998
  • 6
  • 36
  • 57
  • try this: https://stackoverflow.com/a/45351231/2781088 if the answer is helpful. – Mohit Kumar Feb 04 '20 at 06:07
  • I solved this by going the route [@bmjohns answered here](https://stackoverflow.com/questions/28938660/how-to-lock-orientation-of-one-view-controller-to-portrait-mode-only-in-swift) – vikzilla Feb 04 '20 at 18:58

1 Answers1

0

Have you tried to overwrite supportedInterfaceOrientations in your controller? That might help.

Example:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.all
}

Returns all of the interface orientations that the view controller supports.

Apple Doc - supportedInterfaceOrientations

Swift 5.1 short version:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    .all
}
palme
  • 2,499
  • 2
  • 21
  • 38