旋转 UISplitViewController 后模态消失 [英] Modal disappearing after rotating UISplitViewController

查看:19
本文介绍了旋转 UISplitViewController 后模态消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题 UISplitViewController.我的主视图控制器中有一个按钮,点击时会打开一个模态视图(使用简单的故事板 segue).

I have a strange problem UISplitViewController. I have a button in my master view controller which opens a modal view when tapped (using a simple storyboard segue).

但是当我旋转 iPad 时,模态视图消失了,但只有在从纵向旋转到横向时才会消失.我的主视图控制器以纵向隐藏,就像在本机邮件应用程序中一样.

But the modal view disappears when I rotate the iPad, but only when rotating from portrait to landscape. My master view controller is hidden in portrait, like in the native Mail application.

如果我处于横向模式(当母版始终可见)并打开我的模态时,旋转设备可以正常工作并且我的模态保持在屏幕上.

If I'm in landscape (when the master is always visible) and open my modal, rotating the device works correctly and my modal stays on screen.

我尝试以编程方式手动触发 segue,如果我在 splitViewController 上调用 performSegueWithIdentifier:,旋转会双向工作.但我想知道这是否可以通过更简单的方式修复,因为我在主视图控制器中有其他按钮显示模态,我不想为每个按钮执行 IB 操作而失去故事板转场的优势.

I tried manually triggering the segue programmatically, if I call performSegueWithIdentifier: on the splitViewController, rotating works both ways. But I was wondering if this was fixable in a simpler way because I have other buttons displaying modals in the master view controller and I don't want to do an IB action for each one and lose the advantages of storyboard segues.

推荐答案

不幸的是,当你的 ipad 处于纵向模式时,你有一个你的主人的弹出框,它不是另一个形状的主人.这意味着您使用此弹出框作为presentingViewController 呈现一个模态,因此当您从纵向移动到横向时,splitViewController:willShowViewController 方法将使您的弹出框为零,如您所见:

unfortunately it is like that, when your ipad is on portrait mode, you have a popover of your master, it is not the master in another shape. What means that you are presenting a modal using this popover as presentingViewController, so when you move from portrait to landscape the method splitViewController:willShowViewController will make your popover nil as you can see:

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    // Called when the view is shown again in the split view, invalidating the button and popover controller.
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    self.masterPopoverController = nil;
}

所以我理解你的模态是可以接受的.所以,有了这个,你就会明白为什么当你在你的 splitViewController 上调用 performSegueWithIdentifier: 时,它不会发生,你的模态不再与你的弹出框连接.

So I understand that is acceptable that your modal is going with it. So, with this you understand why when you put your action an call the performSegueWithIdentifier: on your splitViewController it doesn't happen, your modal is no longer connected with your popover.

所以你可能会问为什么当你从横向移动到纵向时它不会发生..原因是 splitViewController:willHideViewController,它隐藏了 viewController 它不会删除它,所以你的模态总是连接的.

So you may ask why it doesn't happen when you move from landscape to portrait.. and the reason is splitViewController:willHideViewController, it hides the viewController it doesn't remove it, so your modal is always connected.

不幸的是,没有解决方案,您将不得不通过代码执行操作..

So, unfortunately there is no solution and you will have to perform the actions by code..

希望能帮到你,

罗伯托

这篇关于旋转 UISplitViewController 后模态消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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