当主视图控制器是UITabBarController时,自适应的显示细节序列会转换为模式而不是在iPhone上推送 [英] Adaptive show detail segue transformed to modal instead of push on iPhone when master view controller is a UITabBarController

查看:103
本文介绍了当主视图控制器是UITabBarController时,自适应的显示细节序列会转换为模式而不是在iPhone上推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在XCode 6中,如果您基于Master-Detail Application模板创建一个新项目,那么您将获得一个通用的故事板,应该适用于所有设备.

In XCode 6, if you create a new project based on the Master-Detail Application template, you get a universal storyboard that is supposed to be good for all devices.

在主视图中选择一个单元格时,将通过自适应的显示详细信息"提示来更新详细信息视图.在iPhone 4、5、6或6+纵向肖像上,此序列将按预期采用推送的形式.在横向使用iPad或iPhone 6+的情况下,它将导致详细视图按预期进行更新.

When selecting a cell in the master view, the detail view is updated via an adaptive "show detail" segue. On an iPhone 4, 5, 6 or 6+ in portrait, this segue will take the form of a push as expected. On an iPad or an iPhone 6+ in landscape, it will cause the detail view to be updated as expected.

现在,如果插入UITabBarController作为具有原始主视图控制器选项卡的主视图控制器,则在主视图中选择单元格时发生的自适应选择将无法在iPhone上正常运行.现在,您无需进行推送转换,而是获得模式转换.我该如何解决?似乎奇怪,默认情况下不支持.

Now, if you insert a UITabBarController as the master view controller which has a tab to the original master view controller, the adaptive segue that occurs when selecting a cell in the master view does not behave as expected on iPhones. Instead of getting a push transition, you now get a modal transition. How can I fix that? Seems odd that this is not supported by default.

我发现以下帖子很有用: UISplitviewController主目录中的iOS8 TabbarController 但是,当使用建议的方法时,在推入肖像后旋转到横向时,我在iPhone 6 Plus上无法获得正确的行为.详细视图的内容显示在主视图中,这并不奇怪,因为这是建议的解决方案所要做的.

I found the following post useful: iOS8 TabbarController inside a UISplitviewController Master But when using the suggested method, I don't get the right behaviour on an iPhone 6 Plus when I rotate to landscape after a push in portrait. The content of the detail view appears in the master view which is not surprising since that's what the suggested solution does.

谢谢!

推荐答案

重新观看WWDC14的视频,我想我找到了一个更好的答案.

Re-watching videos from WWDC14 I think I've found a better answer.

  1. 使用自定义UISplitViewController(子类)
  2. 覆盖showDetailViewController操作
  3. 使用traitCollection确定UISplitViewController的类
  4. 如果水平类为Compact,请使navigationController调用showViewController

这是自定义UISplitViewController的代码:

Here is the the code of the custom UISplitViewController :

import UIKit

class CustomSplitViewController: UISplitViewController {

    override func showDetailViewController(vc: UIViewController!, sender: AnyObject!) {

        if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClass.Compact) {
            if let tabBarController = self.viewControllers[0] as? UITabBarController {
                if let navigationController = tabBarController.selectedViewController as? UINavigationController {
                    navigationController.showViewController(vc, sender: sender)
                    return
                }
            }
        }

        super.showDetailViewController(vc, sender: sender)
    }
}

不要忘记在情节提要中设置自定义类.

在iPhone 6,iPhone 6+和iPad Air的模拟器中进行了测试,并按预期工作.

Tested in the simulator of iPhone 6, iPhone 6+ and iPad Air and worked as expected.

这篇关于当主视图控制器是UITabBarController时,自适应的显示细节序列会转换为模式而不是在iPhone上推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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