Rotation problems on iPad

Source: Internet
Author: User

As we all know, the iPhone/iPad application development involves the rotation problem. Of course, the processing of the rotation problem is annoying in some aspects, not because of the complexity, it is not easy to control. In particular, the simultaneous operation of XIB and code will make the problem more complicated. Therefore, we recommend that you use XIB or one of the Code operations as much as possible at the first point of the rotation process. If you do not have to use both methods at the same time. Of course, there is no such thing as a last resort.


The first step of rotation control is to allow your application to support rotation. To ensure that your code supports rotation, we must first process a function:

-(Bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation {
Return yes;
}

This function is used to determine the rotation direction supported by our application. If you want to support each direction, yes is returned directly. After this step is completed, we can solve the rotation problem according to the supported directions. Here we will first look at the functions that can be used to support rotation:

-(Void) willanimaterotationtointerfaceorientation :( uiinterfaceorientation) tointerfaceorientation duration :( nstimeinterval) Duration {
}
-(Void) willanimatefirsthalfofrotationtointerfaceorientation :( uiinterfaceorientation) tointerfaceorientation duration :( nstimeinterval) Duration {
}
-(Void) willanimatesecondhalfofrotationfrominterfaceorientation :( uiinterfaceorientation) frominterfaceorientation duration :( nstimeinterval) Duration {
}
-(Void) willrotatetointerfaceorientation :( uiinterfaceorientation) tointerfaceorientation duration :( nstimeinterval) Duration {
}
-(Void) didrotatefrominterfaceorientation :( uiinterfaceorientation) frominterfaceorientation {
}
-(Void) didanimatefirsthalfofrotationtointerfaceorientation :( uiinterfaceorientation) tointerfaceorientation {
}

These functions can be used to support rotation. Of course, these rotation functions have mutual constraints, that is to say, some rotation functions cannot exist at the same time (this is just what I encountered during the process of doing it, and I will not talk about the specific constraints here ).


Next we will start to solve the problem of rotation. Before specific to each function, we will first talk about the automatic adaptation of various views, as mentioned above, try to avoid processing in XIB and code at the same time. Here we also want to talk about it. If you want to manually control the location, do not set the adaptive size through code, if this is the case, the function supporting rotation may become uncontrollable due to the adaptive adjustment of the size after the position is set.


Next, we will discuss the usage of the above functions.

-(Void) willanimaterotationtointerfaceorientation :( uiinterfaceorientation) tointerfaceorientation
Duration :( nstimeinterval) Duration {
}

This function is executed when the rotation direction changes, but there is a problem. I have tested this function multiple times, and its frame is in the portrait mode, but his statusbarorientation direction has changed. Its direction is consistent with the direction to be rotated.

For other functions, you can obtain the execution time by outputting statusbarorientation and frame. Of course, you can also use them together with several other functions that support rotation to know the execution sequence.

 

Next we should say that the Rotation Processing is correct. Since each function that supports rotation is different from that of frame in its execution direction, we must determine it based on our needs, some functions cannot pass self. view frame parameter value to set, because during the rotation process self. the frame value of the view is unreliable. Therefore, you can set the value, but this method is not convenient. However, specific processing is relatively reliable.

 

We can implement a large number of things to be processed through inheritance, and implement it by placing the sub-view in inheritance, it is better to implement the layoutsubviews function in the subview to achieve the position layout after rotation. However, it should be noted that if the adjusted position is controllable, we recommend that you do not use the adaptive method for the Class View in the inherited class, but set the frame size in the rotated function, in this way, we can adjust the frame of the custom class to the point we want. If this parameter is set, the layoutsubviews function is not necessarily executed after the frame is adjusted, it is executed after it is adjusted in adaptive mode.

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.