Reputation: 238647
I am subclassing UINavigationController
and overriding the supportedInterfaceOrientations
method. In that method, I delegate to the visibleViewController.supportedInterfaceOrientations
.
However, when I present a UIImagePickerController
modally, then visibleViewController
is nil.
Something changed in iOS 10 causing visibleViewController
to return nil.
If I change the code to use presentedViewController
it correctly returns the UIImagePickerController
.
Is this the correct change to make? Why did this change?
Upvotes: 1
Views: 296
Reputation: 47159
It sounds like you could use setOverrideTraitCollection(_:forChildViewController:)
— —
( I would imagine you could implement something similar with the UIImagePickerController
):
func setOverrideTraitCollection(_ collection: UITraitCollection?,
forChildViewController childViewController: UIViewController)
Normally, traits are passed unmodified from the parent view controller to its child view controllers. When implementing a custom container view controller, you can use this method to change the traits of any embedded child view controllers to something more appropriate for your layout. Making such a change alters other view controller behaviors associated with that child. For example, modal presentations behave differently in a horizontally compact versus horizontally regular environment. You might also make such a change to force the same set of traits on the child view controller regardless of the actual trait environment.
↪︎ Video Presentation from WWDC 2016 : Making Apps Adaptive, Part 1 and 2
Apple has recommended to use the newer APIs UITraitCollection
and UITraitEnvironment
over trying to adapt supportedInterfaceOrientations
moving forward...
Upvotes: 1