模态视图可防止其他视图旋转 [英] Modal View prevents other views from rotating

查看:53
本文介绍了模态视图可防止其他视图旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MainViewController中有此方法:

I have this method in my MainViewController:

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"MAIN CONTAINER WILL ANIMATE");
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

当我旋转时,NSLog出现,并且一切都很完美.但是,如果我从MainViewController中显示一个modalViewController,然后旋转,则NSLog将不再出现,并且MainViewController永远都不知道设备旋转了,因此,当modalView关闭时,不会为旋转调整接口.

And when I rotate, the NSLog shows up, and everything is perfect. However, if I present a modalViewController from my MainViewController, and then I rotate, the NSLog no longer appears, and my MainViewController never knows that the device got rotated, so when the modalView is dismissed, the interface is not adjusted for the rotation.

关于模态视图为何会阻止父级接收轮换更新的任何想法?这是典型的情况吗,还是我的设置必须有问题吗?

Any ideas as to why a modal view can prevent the parent from receiving rotation updates? Is this typical, or must there be something wrong with my setup?

为了确保这一点,我尝试通过 [mainViewController.view addSubview:modalView.view] 将modalViewController呈现为子视图,并且轮换更新已正确生效.只有当我执行 [mainViewController presentModalViewController:modalViewController]; 时,更新才会生效.

And just to make sure, I tried presenting the modalViewController as a subview via [mainViewController.view addSubview:modalView.view], and the rotation updates took effect properly. It's only when I do [mainViewController presentModalViewController:modalViewController]; that the updates don't take effect.

推荐答案

当然,当以模态方式显示视图控制器时,其他视图控制器完全不会收到任何消息.在这种情况下,这就是情态的意思.

Surely when a view controller is being presented modally, no other view controllers receive any messages at all. That is what modal means in this context.

显而易见的解决方案是在无模式视图控制器的viewWillAppear方法中检查方向.

The obvious solution would be to check the orientation in the viewWillAppear method of your modeless view controller.

这篇关于模态视图可防止其他视图旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆