Because the rotation will make the interface becomes discordant, unless you have developed a specific interface for a variety of directions, so sometimes it is better to disable rotation, or the program's interface is a horizontal screen, after exiting the horizontal screen view after the screen becomes vertical screen, such as watching video or browsing the Web when you want to be horizontal screen, But the rest of the work you want is a vertical screen. OK, none of this is a problem. We can control the rotation function of each interface in our program through code.
In the view controller you want to set up, find the Shouldautorotatetointerfaceorientation: method, overriding its implementation code:
- [Java]
- -(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation{
- return (interfaceorientation = = Uiinterfaceorientationlandscapeleft);
- }
Copy Code
The system asks this method to try to control whether to rotate to the specified direction. The system is defined in 4 directions, corresponding to 4 kinds of common holding modes:
- [Java]
- typedef enum {
- uiinterfaceorientationportrait = uideviceorientationportrait,
- Uiinterfaceorientationportraitupsidedown = Uideviceorientationportraitupsidedown,
- Uiinterfaceorientationlandscapeleft = Uideviceorientationlandscaperight,
- Uiinterfaceorientationlandscaperight = Uideviceorientationlandscapeleft
- } uiinterfaceorientation;
Copy Code
If you want to support rotation for any situation as long as you return yes, if you want to support only partially, return Yes to the supported return is not supported.
Lan Yi iOS iOS Development automatic rotation control code