Ios 更改方向时正确查看图形,但第一次显示时失败
我在iOS 9中有一个Ios 更改方向时正确查看图形,但第一次显示时失败,ios,uiviewcontroller,landscape,Ios,Uiviewcontroller,Landscape,我在iOS 9中有一个UIViewController,当视图以横向模式显示时,它不能正确绘制 但是,如果视图以纵向模式显示,然后更改为横向,则一切正常 这在模拟器和设备上都会发生。我正在使用Interface Builder设置子视图的高度和约束。我不调整框架大小,也不更新代码中的约束 因此,我试图强制重新绘制类似于改变方向的图,但我无法让它工作,我不确定这是否是最好的方法 有人知道如何解决这个问题吗?在您的ViewController中,您需要覆盖shouldAutorotateToInte
UIViewController
,当视图以横向模式显示时,它不能正确绘制
但是,如果视图以纵向模式显示,然后更改为横向,则一切正常
这在模拟器和设备上都会发生。我正在使用Interface Builder设置子视图的高度和约束。我不调整框架大小,也不更新代码中的约束
因此,我试图强制重新绘制类似于改变方向的图,但我无法让它工作,我不确定这是否是最好的方法
有人知道如何解决这个问题吗?在您的ViewController中,您需要覆盖shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)方法,以便在应用程序旋转时返回YES:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}