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);}