iOS screen rotation

Source: Internet
Author: User
<span id="Label3"></p><span style="font-size:18px">Accelerometer is the basis of the entire iOS screen rotation, relying on the accelerometer, the device can determine the current device orientation, The IOS system has defined the following seven device orientations:<br><br>typedef ns_enum (nsinteger, Uideviceorientation) {<br>uideviceorientationunknown,<br>Uideviceorientationportrait,//Device oriented vertically, home button on the bottom<br>Uideviceorientationportraitupsidedown,//Device oriented vertically, home button on the top<br>Uideviceorientationlandscapeleft,//Device oriented horizontally, Home button on the right<br>Uideviceorientationlandscaperight,//Device oriented horizontally, home button on the left<br>Uideviceorientationfaceup,//Device oriented flat, face up<br>Uideviceorientationfacedown//Device oriented flat, face down<br>};<br>And the following four kinds of interface directions:<br><br>typedef ns_enum (nsinteger, Uiinterfaceorientation) {<br>uiinterfaceorientationportrait = uideviceorientationportrait,<br>Uiinterfaceorientationportraitupsidedown = uideviceorientationportraitupsidedown,<br>Uiinterfaceorientationlandscapeleft = uideviceorientationlandscaperight,<br>Uiinterfaceorientationlandscaperight = Uideviceorientationlandscapeleft<br>};<br><br>Uikit process for processing screen rotation<br><br>When the accelerometer detects a change in direction, a uideviceorientationdidchangenotification notification is issued so that any view that is concerned about a change in direction can be responded to by registering the notification and changing the device Direction. In the previous blog, we have already mentioned that when the screen rotates, Uikit helps us do a lot of things to make it easier for us to finish the screen Rotation.<br><br>The process for the corresponding screen rotation of the uikit is as Follows:<br><br>1, when the device rotates, Uikit receive the rotation event.<br><br>2, Uikit through Appdelegate notify the current program WINDOW.<br><br>3, window will know its rootviewcontroller, determine the direction of rotation supported by the view controller, complete the Rotation.<br><br>4, If there is a pop-up view controller, the system will be based on the pop-up view controller, to determine whether to Rotate.<br><br><br><br>second, Uiviewcontroller to achieve screen rotation<br><br>In response to device rotation, we can achieve finer-grained control through the Uiviewcontroller method, when the view controller receives a change in the direction of the window, the process is as Follows:<br><br>1, First judge whether the current Viewcontroller support rotation to the target direction, if supported to enter the process 2, otherwise the rotation process directly ended.<br><br>2, Call Willrotatetointerfaceorientation:duration: method, notify the view controller will be rotated to the target Direction. If the Viewcontroller is a container view controller, it will continue to invoke the method of its content view Controller. At this time we can also temporarily hide some of the view, and so on after the rotation of the reality come Out.<br><br>3, window adjusts the display Controller's bounds, because the view controller's bounds changes, will trigger the Viewwilllayoutsubviews Method. This time self.interfaceorientation and statusbarorientation direction is still the same direction.<br><br>4, then the current view Controller's Willanimaterotationtointerfaceorientation:duration: method will be Called. The system will place all of the property changes performed in the method into the dynamic animation block.<br><br>5, the execution direction rotation Animation.<br><br>6, the Last Call Didrotatefrominterfaceorientation: method, notify the View controller rotation animation execution is Complete. This time we can show the second hidden view again.<br><br>The entire response process is as Follows:<br><br><br><br>    <br><br>The above is uikit the next full screen rotation process, We just need to follow the prompts to do the appropriate processing can be perfect to support screen Rotation.<br><br><br><br>Iii. Considerations and Recommendations<br><br>1) precautions<br><br>When our view controller is hidden, the direction of the device may Change. For example, when View Controller a pops up a Full-screen view controller b, The screen rotation message is not received because A is completely invisible. This time if the screen direction changes, and then dismiss b, the direction of a will be incorrect. We can fix this problem by updating the direction in view controller A's viewwillappear.<br><br>2) some suggestions when the screen rotates<br><br>The response of the temporary interface operation during the Rotation.<br>Before and after rotation, try to display the current position Unchanged.<br>For more complex view levels, to improve efficiency, replace the current view level before rotation, and then replace the original view level with the Rotation.<br>It is best to force reload TableView after rotation to ensure that the new row is full-screen after the direction changes. For example, some photo-display interface, vertical screen display only one column, but the horizontal screen when the list interface, this time an interface will show more elements, when the reload content is very necessary.</span><p><p>iOS screen rotation</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.