3

考虑一个UIViewController基于其状态支持不同界面方向的界面,该状态可以根据用户输入而改变。

AFAIK,supportedInterfaceOrientations仅在设备方向更改时调用。有没有办法告诉应用程序它需要再次询问支持的界面方向,即使设备方向没有改变?

4

1 回答 1

1

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.

于 2012-12-02T00:39:36.837 回答