On iOS, why is shouldAutorotateToInterfaceOrientat

2019-08-26 15:59发布

If a Single View app is created for iPad, depending on the Supported Device Orientation is set for the plist, and what shouldAutorotateToInterfaceOrientation returns, shouldAutorotateToInterfaceOrientation can be called 10, 12, or even 13 times.

One simple case is, if the "Support Device Orientation" is set to Landscape Left, and shouldAutorotateToInterfaceOrientation also returns YES only for Landscape Left, then if I start the app in Landscape Left orientation, then shouldAutorotateToInterfaceOrientation will be called 12 times in a row. If I hold it in other orientation and start the app, then it is 13 times.

What is the reason that it is called so many times in a row?

1条回答
贼婆χ
2楼-- · 2019-08-26 16:47

As i can see at UIDevice.h, orientation type is not used as a mask and several requests should be performed:

  • check whether the current orientation is supported
  • if not, find the supported orientation with 1-3 or 1-4 requests

The whole process could happen more than one time for a single orientation change (e.g. the system might want to send the correct notification to the application window the status bar might want to check the orientation independently, welcome to OOP, i'm not saying it happens, but it might) while the results of the 1st or 2nd stages might be somehow cached by one component and not by another.

查看更多
登录 后发表回答