10

On iOS 13, pushing a view controller using segue such as "Show" causes supportedInterfaceOrientations not to be called on presented view controller(VC2). As a result, the controller autorotates to portrait mode even though supportedInterfaceOrientations returns only .landscape. However, if we push another view controller(VC3) from this controller(VC2) via any segue, VC3 does not autorotate.

The only workaround I have found is presenting VC2 as modal view controller using modal presentation style fullScreen. This is not I want on iPad devices, so looking for the reason why it is happening this way on iOS 13 and a fix.

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

1 Answers1

8

You have to set the 'presentation style' on the view controller to Full Screen, then the supportedInterface override will get called.

Story board

or check out this for even more info

How to present a modal atop the current view in Swift

John Lanzivision
  • 425
  • 4
  • 12
  • I just tried this (Xcode 12.4/Swift 5/iOS 12.4) with a regular `UIViewController` (was set to "Automatic" before) with a "show" segue but the function still wasn't called. – Neph Apr 12 '21 at 12:46
  • Do you have all this under a nav controller? If so that may be intercepting the change – John Lanzivision Apr 13 '21 at 19:09
  • No, not directly at least. There's one opening "View Controller 2" but VC3 and VC4 (this one I want to prevent orientation changes for) are opened with a segue (`performSegue`, it's VC2 -> VC3 -> VC4). There's also a VC1 that I didn't want user to turn either but having the code in it's class didn't work either - I had to create a class for the initial `UINavigationController` that loads VC1 and add the code there. But that controller loads the VC directly, not through multiple segues like with VC4. – Neph Apr 14 '21 at 08:57