Search code examples
iosrotationuiinterfaceorientation

iPhoneXR returning to rootview controller after rotation


I currently have a bug that has been reported only on the iPhone XR.

We have a custom camera that forces the rotation into Landscape, and when it is complete, it forces the view back to portrait.

The bug has only been mentioned by users with an iPhone XR. It happens after calling a forced rotation and pop view controller. Rather than returning back to the previous view, it goes back over three view controllers to the root view controller. (edit: From what I can tell the other view controllers aren't called/displayed/loaded at all)

I found this bug happened even when we didn't call..

self.navigationController?.popViewController(animated: true)

So the issue happens specifically with this line..

UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")

Then after disabling this line, the next screen appears in landscape. BUT if I rotate my phone physically to portrait, it jumps back to the root view controller again.

Notes

  • I have confirmed on iPhone 6s and older devices this bug doesn't happen.
  • I cannot test camera features on the emulator which is frustrating.
  • I have zero code in my app that calls any returns to the root controller.
  • There is a split view controller at the root of this

Is there some new feature I am unaware of, why would a rotation call on new phones return to the root view controller?

Update: This is my current lead on the issue. Popover Nil On Rotation


Solution

  • So I found a solution which I am posting, not to discount matt's response which offers great insight into better practice.

    The problem was the Split View Controller when rotating on newer devices makes the popover's nil, hence returning to the root. I found the explanation on this behavior here - Modal disappearing after rotating UISplitViewController

    In short I removed the Split View Controller and will be searching for a better alternative to support iPads.