更改方向时正确查看图纸,但在首次显示时失败

时间:2016-01-19 07:46:04

标签: ios uiviewcontroller landscape

我在iOS 9中有UIViewController,当视图以横向模式显示时无法正确绘制。

但是,如果视图以纵向模式显示,然后更改为横向,则一切正常。

在模拟器和设备上都会发生这种情况。我正在使用Interface Builder来设置子视图的高度和约束。我没有对帧大小进行任何大小调整或对代码中的约束进行更新。

所以我试图强制重新绘制类似于方向的更改,但我无法让它工作,我不确定这是否是最好的方法。

有没有人知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

在ViewControllers中,您需要覆盖shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)方法,以便在应用旋转时返回YES:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

     return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}