iOS screen rotation direction related methods

Source: Internet
Author: User

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

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.