IOS default start direction

Source: Internet
Author: User

Apps developed by iOS can change the direction of their mobile phones at Will (UIInterfaceOrientation). Generally, ViewController's-(BOOL) shouldAutorotateToInterfaceOrientation will help you:

1 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation2 {3     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);4 }

If you create a simple Window-base Application in XCode, the code above will help you automatically adjust the entire view direction when you rotate the phone. However, if you observe the TARGETS of the project, Portrait, Landscape Left, and Landscape Right are selected under Supported Device Orientations under Summary.

Now we have two questions. If you develop a horizontally-qualified ARPG game (similar to the previous arcade game "Three Kingdoms"), the game must be in the Landscape state when it is started, and cannot be in the Portrait status. If you develop a vertical flying shooting game (similar to the previous arcade game "Caijing 1945"), the game must be in the Portrait State and cannot be in the Landscape state. What should I do now?

There are two main points for the above problem. One is to start the program in the specified method (Landscape or Portrait) when it starts, and the other is to keep the program running in one direction after it starts.

Specific solutions (the following uses horizontal pass game as an example ):

1. deselect all options under Supported Device Orientations in TARGETS of the project.

2. Add "Initial interface orientation" to the Info page in TARGETS and specify a non-horizontal direction (for example, Landscape (right home button ))

3. Modify the shouldAutorotateToInterfaceOritentation function,

1 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation2 {3     return UIInterfaceOrientationIsLandscape(interfaceOrientation);4 }

For vertical applications, because Initial interface orientation is Portrait by default, you do not need to set this item. You only need to modify the shouldAutorotateToInterfaceOrientation function to start a vertical game:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return UIInterfaceOrientationIsPortrait(interfaceOrientation);}
Related Article

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.