shouldAutorotateToInterfaceOrientation called several times in a row without any rotation

谁说我不能喝 提交于 2020-01-14 03:36:05

问题


I am trying to implement some interface changes in my app, based on the device rotation.

My app is a view based app. So, its main view controller has a didload method.

The app starts in portrait. Almost all changes on the device orientation triggers the shouldAutorotateToInterfaceOrientation method but this method is not called when the device is put on portrait, after coming from any landscape orientation.

While debugging the app, I have put a

NSLog(@"orientation=%d", interfaceOrientation);

on my shouldAutorotateToInterfaceOrientation method, and what I see is quite strange:

  • When I run the app, shouldAutorotateToInterfaceOrientation is called 6 times before the app's interface even appears. Every time it runs, it reports a different number for the orientation: the order it reports on console is: portrait, portrait, portrait, landscape right, landscape left, upside down) (????).

During this time the app is just beginning. The debugger reports all 6 calls coming from the app's delegate.

So, here comes the questions:

  1. WHy shouldAutorotateToInterfaceOrientation is not being called when the device enters on portrait?
  2. Why is the delegate calling this method 6 times before the app's is even visible, specially when no rotation is being done?

thanks.


回答1:


The UIViewController Class Reference seems to say that this method returns a value "indicating whether the view controller supports the specified orientation".

It doesn't make any promises that the device is/isn't rotating right now, it's just querying to see what orientations your controller can support. Hence the statement:

Your view controller is either capable of supporting a given orientation or it is not.




回答2:


The system is caching the responses so it knows what orientations to try and detect.



来源:https://stackoverflow.com/questions/2621702/shouldautorotatetointerfaceorientation-called-several-times-in-a-row-without-any

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!