What should I do if the view is messy due to landscape switching?
First, we must understand the following four statuses, which are used to describe the orientation of the device:
Uiinterfaceorientationlandscapeleft |
To the left, that is, the Home key is in the right |
Uiinterfaceorientationlandscaperight |
Right, that is, the Home key is on the left |
Uiinterfaceorientationportrait |
Upright, that is, the Home Key is down |
Uiinterfaceorientationportraitupsidedown |
Inverted, that is, the Home Key is on |
The process of rotating screens is roughly divided into the following situations and ideas:
Maybe you don't need the support for rotating screens, but want to lock the screen
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return NO;}
You may need to support rotating screens or rotating screens in some directions.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}
Maybe your view has a background image. When you rotate the screen, the system helps you stretch the image, but it does not care about other components, such as the button. You want to directly change the size and position of the button.
-(Void) Duration :( uiinterfaceorientation) tointerfaceorientation duration :( nstimeinterval) Duration {If (duration (tointerfaceorientation) {nslog (@ ""); [BTN setframe: cgrectmake (213,442,340, 46)];} If (uiinterfaceorientationislandscape (tointerfaceorientation) {nslog (@ "currently landscape screen"); [BTN setframe: cgrectmake (280,322,460, 35)] ;}}
Maybe you don't want to use absolute coordinates to constrain the control, but want it to adapt to the screen rotation by rotating itself
-(Void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view, typically from a nib. uidevice * Device = [uidevice currentdevice]; [device identifier]; // use nsicationicationcenter to obtain the rotation signal. Optional nsnotificationcenter * ncenter = [nsicationicationcenter defacenter center]; [ncenter addobserver: Self selector: @ selec Tor (orientationchanged) Name: uideviceorientationdidchangenotification object: Device];}-(bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation {return (interfaceorientation! = Uiinterfaceorientationportraitupsidedown);}-(void) rotation_btn :( float) n {uibutton * robtn = self. BTN; robtn. transform = transform (N * m_pi/180.0);}-(void) orientationchanged {uideviceorientation orientaiton = [[uidevice currentdevice] orientation]; Switch (orientaiton) {detail: [self rotation_btn: 0.0]; break; weight: [self rotation_btn: 90.0*2]; break; weight: [self rotation_btn: 90.0*3]; break; caseuideviceorientationlandscaperight: [self rotation_btn: 90.0]; break; default: break ;}}
Maybe you need autoresizessubviews = Yes
Maybe you want different la ing effects on the horizontal and vertical screens. You need to prepare two subviews and replace them in different States.
Of course, do not forget. You need to adjust the positions 1 and 2 in the settings diagram,
To help us achieve the desired adaptation effect. The example animation is clearly displayed. ^ _ ^ I will not be jealous any more.