In the viewcontroller you want to support the screen, rewrite two methods:
// 支持设备自动旋转
- (
BOOL
)shouldAutorotate
{
return
YES;
}
// 支持横竖屏显示
- (NSUInteger)supportedInterfaceOrientations
{
return
UIInterfaceOrientationMaskAll;
}
In this viewcontroller, you can switch between the screen.
However, if your window's Rootviewcontroller is a navigationcontroller, the following issues may occur:
Navigationcontroller only support vertical screen, but you push to a new controller, this controller supports the horizontal screen, When you switch to a horizontal screen in a new controller (it is also possible to switch to a horizontal screen and then pop back), the program will blink because your navigationcontroller does not support horizontal screen.
This requires writing a uinavigationcontroller subclass, overriding the method in this class:
- (
BOOL
)shouldAutorotate
{
return
[self.viewControllers.lastObject shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return
[self.viewControllers.lastObject supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return
[self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
Then use this class to create an instance as the window's Rootviewcontroller, so you can avoid this problem.
iOS turn off the horizontal screen after a single page to toggle the screen