1. To do the vertical and horizontal screen adaptation, you need to determine whether the current state is a flat screen or portrait screen, there are two ways:
1th type: [UIScreen mainscreen].bounds.size.width = = 768
Advantages: After this macro, can judge the screen at any time, #define LANSCAPE ([uiscreen mainscreen].bounds.size.width = = 768)
Disadvantage: Only in iOS8 feasible, that is, in the iOS8 horizontal screen of the width=1024, vertical screen width=768; And on the iOS7, the width=768 of the screen
2nd type:-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation Duration: ( Nstimeinterval) duration
When the screen rotates, the method is called automatically, simply by overriding the method on the root controller
-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation Duration: (NSTimeInterval ) duration
{
BOOL landscape = Uiinterfaceorientationislandscape (tointerfaceorientation); //Judging is not horizontal screen
[Sub-view 1 Rotate:landscape]; public methods for//Sub-view 1
[Sub-view 2 rotate:landscape]; Public methods for child view 2
}
In sub-view 1, to implement the-(void) Rotate: (BOOL) Landscape method
-(void) Rotate: (BOOL) Landscape
{
if ( landscape) {
//Horizontal screen case, what is the frame
} else {
//Vertical screen case, what is the frame
}
//If you have a child view in sub-view 1, you can
[Child View 1 sub-view a rotate:landscape];
[Child View 1 sub-view B rotate:landscape];
}
There may be a lot of views that need to respond to the screen, so you can-(void) Rotate: (BOOL) landscape, as long as the agreement, you have the declaration of the method, the implementation of the Protocol method itself.
Advantages: Ios7\8 are feasible
Cons: More cumbersome
2. Additional Information
When the screen rotates, the window will know that the window then tells the root controller, and then the root controller to the child controller, the sub-controller is passed to the sub-controller, so the controller's view to respond to screen rotation events, by looking for the parent controller, a layer of layers to look up, and finally to find the window to line.
IOS ipad Development with the right and down screen fit