hpique
hpique

Reputation: 120344

Reload supported interface orientations in iOS

Consider a UIViewController that supports different interface orientations based on its state, which can change based on user input.

AFAIK, supportedInterfaceOrientations is only called when the device orientation changes. Is there a way to tell the application that it needs to ask again about the supported interface orientations, even if the device orientation didn't change?

Upvotes: 3

Views: 1110

Answers (1)

David
David

Reputation: 1152

You're correct. Basically you can only respond to an orientation change, not force it. But there is a trick you can use to fool the application to go through all the orientation callbacks.

You should have a ViewController which you created at the start of your app and set as the window's rootViewController. Remove that ViewController's view from its superview (which is the window) and immediately add it as a subview to the window again. Since the entire visible view hierarchy just changed, the app will go through all orientation callbacks again.

But I wouldn't rely on this too much if I were you, while it is logical for this to happen, you never know when Apple might change this. Now that I think of it, I haven't tested this in iOS 6 yet. It does work on iOS 4 and 5.

Upvotes: 1

Related Questions