iOS single page setting horizontal screen

In our development, we sometimes need to set up horizontal screen browsing, especially the video playback page is often used to horizontal screen, and it is also the most used to switch back and forth between horizontal screen and vertical screen.

So how should we set and adapt to the horizontal screen? ? ?

 1. Enter the page default horizontal screen effect

  1. Set page screen orientation
  2. Set the supported orientation of the page screen
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight;
}//页面需要的横屏方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
}//页面支持屏幕横屏的方向

 Add the setting of page B, page A enters page B, page B is horizontal, but it should be noted that only

[self presentViewController:vc animated:YES completion:nil] This will take effect when entering the B page, and the push entry will not take effect

2. Code to manually set the horizontal screen

  1. Set page screen orientation
  2. Set the supported orientation of the page screen
  3. Manual call
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight;
}//页面需要的横屏方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
}//页面支持屏幕横屏的方向

// 改变页面屏幕方向的方法
- (void)forceToOrientation:(UIDeviceOrientation)orientation
{
    NSNumber *orientationUnknown = [NSNumber numberWithInt:0];
    [[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];

    NSNumber *orientationTarget = [NSNumber numberWithInt:orientation];
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}

Click the button to call to set the screen orientation

- (void)changeUIDeviceOrientation:(UIButton *)sender {
   [self forceToOrientation:UIDeviceOrientationLandscapeRight];
}

Setting in viewDidLoad can also enter the page automatically horizontal screen (push)

- (void)viewDidLoad {
    [super viewDidLoad];

	[self forceToOrientation:UIDeviceOrientationLandscapeRight];

}

 

Guess you like

Origin blog.csdn.net/zjpjay/article/details/103984174
Recommended