- Uiviewcontroller Force Vertical screen:
If you want the entire app vertical screen, you can write a Baseviewcontroller
1 First rewrite the following method in APPDELEGATE.M
-(uiinterfaceorientationmask) Application: (uiapplication *) application Supportedinterfaceorientationsforwindow: (uiwindow *) window
{
Back to the screen orientation you want to support, if only vertical screen is supported, directly return to vertical screen macro
}
2 in the Uiviewcontroller
-(void) Viewwillappear: (BOOL) animated{
Interfaceorientation defined for direction macros
[[uidevice currentdevice] setValue: [nsnumber numberwithinteger: Interfaceorientation] forkey:@ "orientation"];
}
- Overall vertical screen, but the individual interface requires a horizontal screen
If there are individual interfaces in the interface that require a horizontal screen, you can add a flag to control the return value of the Supportedinterfaceorientationsforwindow, such as:
-(uiinterfaceorientationmask) Application: (uiapplication *) application Supportedinterfaceorientationsforwindow: (uiwindow *) window
{
if (! Self. Allowrotation) {
return uiinterfaceorientationmaskportrait;
}
return uiinterfaceorientationmasklandscaperight; // interface can only be rotated to the right
}
And then in the Uiviewcontroller code you need to cross-screen the following implementation: (Remember the horizontal screen flag bit value setting)
-(void) Viewwillappear: (BOOL) animated
{
[Super viewwillappear: animated];
[[uidevice currentdevice] setValue: [nsnumber numberwithinteger: Uiinterfaceorientationlandscaperight] forkey:@ "orientation"];
}
Preferredinterfaceorientationforpresentation This method is not the same as the definition of different iOS versions.
<IOS9:
-(nsuinteger) preferredinterfaceorientationforpresentation {
return uiinterfaceorientationportrait;
}
>=ios9
-(uiinterfaceorientationmask) supportedinterfaceorientations {
return uiinterfaceorientationmaskportrait;
}
Note If you override the Supportedinterfaceorientations method, there is a problem with switching from horizontal to vertical in the IOS7 version of the screen. I was rewriting it in Uiviewcontroler.
-(uiinterfaceorientationmask) supportedinterfaceorientations
Finally, in order to resolve the IOS7 version of the problem, you need to remove the rewrite as above.
Also note that the Interfaceorientation property inside the Uiviewcontroller is not recommended after IOS8.
iOS Screen Toggle Summary