I have a user setting in my application which is supposed to set the orientation of specific view controllers to either landscape or portrait. The user presses a button on the main screen to toggle landscape/portrait for the other view controllers in the app by setting a global variable which should be read by the other controllers.
I have extended the UINavigationController as follows:
extension UINavigationController {
public override func supportedInterfaceOrientations() -> Int {
return visibleViewController.supportedInterfaceOrientations()
}
}
I have also tried changing the visibleViewController to topViewController with no luck.
In all of my UIViewController files I then override the function:
override func supportedInterfaceOrientations() -> Int {
return appOrientation // global user setting
}
The problem is that the only view controller that ever gets this function called is the main view controller (the first view the user sees and where the user can select the orientation). Why does this function not get called in the subsequently pushed view controllers?
The global appOrientation variable is set to either of the following when the user toggles it:
let orientationPortrait = Int(UIInterfaceOrientationMask.Portrait.rawValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue)
let orientationLandscape = Int(UIInterfaceOrientationMask.Landscape.rawValue)
If I return one of these defines in the main view controller's supportedInterfaceOrientation function, the entire app is oriented to the define (not what I want).
I must be missing something here.