During iOS app development, you'll often encounter setting the screen orientation, or changing the interface depending on the screen orientation, so now it's time to take a look at those things in the screen orientation.
For directions, you will often encounter the following two objects:
1.UIDeviceOrientation (direction of machine equipment)
==================================
Uideviceorientationunknown// Unknown Direction
uideviceorientationportrait, //device upright, home button under
Uideviceorientationportraitupsidedown, //device upright, home button on top
Uideviceorientationlandscapeleft, //device horizontal, Home button on right
Uideviceorientationlandscaperight, //device horizontal, Home button on left
Uideviceorientationfaceup, //device flat, screen facing up
Uideviceorientationfacedown //Device flat, on screen facing down
==================================
2.UIInterfaceOrientation (the direction of the interface, after IOS6 can go to see Uiinterfaceorientationmask )
==================================
Uiinterfaceorientationportrait//Vertical, home button next
Uiinterfaceorientationportraitupsidedown//Vertical, home button on top
Uiinterfaceorientationlandscapeleft//Landscape, home button on left
Uiinterfaceorientationlandscaperight//Landscape, home button on right
==================================
the development of interface is mainly used uiinterfaceorientation
I. Getting the current interface orientation
Two. The method that will be called when the interface direction changes
-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation Duration: ( Nstimeinterval) Duration {}//view rotation is automatically called before
-(void) Willanimaterotationtointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation Duration: ( Nstimeinterval) Duration {}//automatically called when rotation direction changes
-(void) Didrotatefrominterfaceorientation: (uiinterfaceorientation) frominterfaceorientation automatically called after the}//view rotation is complete
three. Set the orientation of the interface support1. Global Settings
1.1 Engineering Setup (XCODE5 for example)
Targets->general->deploymentinfo->device Orientation to set
1.2 Set in APPDELEGATE.M (after iOS6)
-(nsuinteger) application: ( uiapplication *) Application Supportedinterfaceorientationsforwindow: (uiwindow *) window{
return uiinterfaceorientationmaskportrait;
}
2. General setting of a single interface
after IOS6:
-(BOOL) shouldautorotate{
return YES;
}//Whether rotation is supported
-(nsuinteger) supportedinterfaceorientations{
return uiinterfaceorientationmasklandscaperight;
}//Supported directions
Before IOS6:
-(BOOL) shouldautorotatetointerfaceorientation: ( uiinterfaceorientation ) tointerfaceorientation{
return tointerfaceorientation = = uiinterfaceorientationlandscaperight;
}
3. Special Cases
Referring to the Uinavigationcontroller, the view that needs to be changed is Uinavigationcontroller Rootviewcontroller
Then you need to create a new subclass of Uinavigationcontroller (of course, the view that you want to change is the rootviewcontroller of that subclass), and add the following method to the subclass
-(BOOL) shouldautorotate
{
return self.topViewController.shouldAutorotate;
}
-(Nsuinteger) supportedinterfaceorientations
{
return self.topViewController.supportedInterfaceOrientations;
}
Then set the 2 for each view individually
Reference Links:
1.http://blog.csdn.net/zzfsuiye/article/details/8251060
2.http://www.cocoachina.com/applenews/devnews/2012/1218/5364.html
3.http://my.oschina.net/louwk/blog/203084