The processing method of iOS9 screen setting

Source: Internet
Author: User

In the general Video class app will support horizontal screen when playing, so the advantage is easy to watch. Do you support horizontal screen in your project? Let us know together, in the iOS9 of the screen set the way to handle it!

Support Screen Configuration

After IOS6, if the app needs to support horizontal screen, you need to check the configuration in the Xcode settings:

After the configuration is complete, we can take a look at the supported interface orientations option in info.plist and change accordingly. Such as:

Of course, we can also configure directly in the Info.plist.

Support for the screen method

We can configure this method directly before IOS6:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0) __TVOS_PROHIBITED; 

After the IOS6, the method was Ns_deprecated_ios, which was discarded. By discarding this method, Apple has also given new ways to replace it:

New autorotation support.-(BOOL) shouldautorotate Ns_available_ios (6_0) __tvos_prohibited;-( Uiinterfaceorientationmask) supportedinterfaceorientations Ns_available_ios (6_0) __TVOS_PROHIBITED;

We can see that iOS6 before is a method, after IOS6 becomes two methods, one is whether to rotate the method, one is to support the direction of the method.

Example one:

Suppose: Our Viewcontroller is loaded directly above the Self.window.rootViewController of the window. The code is as follows:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions {     // Override point for customization after application launch.    Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];     *VC = [[Viewcontroller alloc] init];     = VC;    [Self.window makekeyandvisible];     return YES;}

What if we want to support the direction of the above general check (vertical screen, horizontal screen to the left horizontal screen to the right)? First, we should set the direction that allows him to support rotation and then set in support. The code is as follows:

1 //Support Rotation2-(BOOL) shouldautorotate{3    returnYES;4 }5 //direction of support6-(Uiinterfaceorientationmask) supportedinterfaceorientations {7     returnUiinterfaceorientationmaskallbutupsidedown;8 }9 where Uiinterfaceorientationmask is an enumeration:Ten  One typedef ns_options (Nsuinteger, uiinterfaceorientationmask) { AUiinterfaceorientationmaskportrait = (1<<uiinterfaceorientationportrait), -Uiinterfaceorientationmasklandscapeleft = (1<<uiinterfaceorientationlandscapeleft), -Uiinterfaceorientationmasklandscaperight = (1<<uiinterfaceorientationlandscaperight), theUiinterfaceorientationmaskportraitupsidedown = (1<<uiinterfaceorientationportraitupsidedown), -Uiinterfaceorientationmasklandscape = (Uiinterfaceorientationmasklandscapeleft |uiinterfaceorientationmasklandscaperight), -Uiinterfaceorientationmaskall = (uiinterfaceorientationmaskportrait | Uiinterfaceorientationmasklandscapeleft | Uiinterfaceorientationmasklandscaperight |uiinterfaceorientationmaskportraitupsidedown), -Uiinterfaceorientationmaskallbutupsidedown = (uiinterfaceorientationmaskportrait | Uiinterfaceorientationmasklandscapeleft |uiinterfaceorientationmasklandscaperight), +} __tvos_prohibited;

Can choose according to their own needs. Above we say that assuming this condition, if rootviewcontroller on the navigation, we directly in the Viewcontroller inside set, this method is not the spirit. (You can test it yourself)

Example two:

Why is the navigation above the method is not the spirit? The reason is very simple, we do not set the direction of navigation support. Don't forget that Uinavigationcontroller is also a uiviewcontroller subclass. Need to be treated the same way.

How do I set it? We can create a subclass of Uinavigationcontroller, assuming it's called Ggpublicnavigationviewcontroller. Then we implemented two methods in the GGPUBLICNAVIGATIONVIEWCONTROLLER.M file:

 1  //  2 - (BOOL) shouldautorotate{ 3  return   YES;  4   5  //  supported direction  - (Uiinterfaceorientationmask) supportedinterfaceorientations { 7  return   Uiinterfaceorientationmaskallbutupsidedown;  8 } 

After this setting, even if we push in the Uiviewcontroller does not implement the above method, it can also support the horizontal screen. In other words, all of our push support is horizontal screen. This practice is not very violent!

Example three:

Some children's shoes will ask, how to control the direction of each interface support? This is also possible, in Ggpublicnavigationviewcontroller can not write dead support which. We can write this:

1 -(BOOL) shouldautorotate{2     return  [Self.topviewcontroller Shouldautorotate]; 3 }4// supported direction 5 - (Uiinterfaceorientationmask) supportedinterfaceorientations {6     return  [Self.topviewcontroller Supportedinterfaceorientations];; 7 }

Self.topviewcontroller is the current navigation display of the Uiviewcontroller, so you can control the direction of each Uiviewcontroller support!

The processing method of iOS9 screen setting

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.