Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改方向时正确查看图形,但第一次显示时失败_Ios_Uiviewcontroller_Landscape - Fatal编程技术网

Ios 更改方向时正确查看图形,但第一次显示时失败

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

我在iOS 9中有一个
UIViewController
,当视图以横向模式显示时,它不能正确绘制

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

这在模拟器和设备上都会发生。我正在使用Interface Builder设置子视图的高度和约束。我不调整框架大小,也不更新代码中的约束

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


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

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

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