If the app supports rotation, it will almost certainly involve the autosizing problem of uiview.
There are two methods for autosize:
First, set it in the Nb size inspectator property panel.
First, use code to set the autoresizingmask attribute of uiview
Note: For margin, the settings in Nb are logically different from those in code settings.
Example:
The position of the uiview in the upper left corner of the screen (top & left) remains unchanged,
If you want code, it should be
Subview. autoresizingmask = uiviewautoresizingflexiblebottommargin | uiviewautoresizingflexiblerightmargin;
The corresponding Nb settings are:
To use uiview, the upper, lower, and left margin values are flexable (that is, when rotate is used, the upper, lower, and left margin values must be adjusted)
If you want code, it should be
Subview. autoresizingmask = uiviewautoresizingflexiblebottommargin | uiviewautoresizingflexibletopmargin | contents | uiviewautoresizingflexiblerightmargin;
The corresponding Nb settings are:
For uiview, the upper, lower, and left margin are fixed. (If you want uiview to rotate without autosizing, that is, manually write code to set the position and size, you should use this)
If you want code, it should be
Subview. autoresizingmask = uiviewautoresizingnone;
The corresponding Nb settings are:
With the above settings, you may also need to manually write code to set the location and size of the uiview, Example
View1.frame = cgrectmake (10, 10,
100,100 );
We recommend that you write the code for setting the uiview frame in willanimaterotationtointerfaceorientation, while the shouldautorotatetointerfaceorientation method is used to set the supported rotation directions.
Note: willanimaterotationtointerfaceorientation will not be called when the app is started. It will only be called after rotation, and shouldautorotatetointerfaceorientation will also be called at startup and will be called more than once!
Example:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ NSLog(@"shouldAutorotateToInterfaceOrientation"); return YES;}- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ NSLog(@"willAnimateRotationToInterfaceOrientation"); if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { view1.frame=CGRectMake(10, 10, 100, 100); } else { view1.frame=CGRectMake(50, 50, 50, 50); } }
Ref links:
Http://www.cnblogs.com/xingchen/archive/2012/02/29/2374798.html
Http://www.techotopia.com/index.php/IOS_4_iPhone_Rotation,_View_Resizing_and_Layout_Handling
Http://blog.csdn.net/yuquan0821/article/details/7596545
Http://www.cocoachina.com/bbs/read.php? Tid = 98457
Http://hi.baidu.com/rslhg/blog/item/c5338dbf03fa701318d81f64.html