强制横屏以后控件布局问题

页面强制横屏

强制某个页面进入就是横屏状态其实只要两个简单的操作就完成了。 

首先进入targets页面,点击General栏,在DeploymentInfo中只勾选Portrait选项,如图所示:

然后在需要横屏的VC中添加以下代码:

#pragma mark - 设置横屏
- (BOOL)shouldAutorotate{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

布局问题

对页面进行强制横屏操作,在viewDidLoad和viewWillAppear两个生命周期中布局是和正常的完全一样的,但在接下来的生命周期中,[[UIScreen mainScreen] bounds].size.width会和height互换。比如说在iPhone8中,此时[[UIScreen mainScreen] bounds].size.width变成了667,而[[UIScreen mainScreen] bounds].size.height变成了375。所以在之后的布局中要注意这一点。

猜你喜欢

转载自blog.csdn.net/u012380572/article/details/81111802