本文介绍了iPhone上的UISplitViewController纵向始终显示iOS 8中的主图和细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UISplitViewController 始终在 iOS 8

我尝试继承 UISplitViewController 并将其配置为同时显示主数据和详细信息。但没有任何影响。

I try to subclass UISplitViewController and config it to show master and detail at the same time. but no any effect.

class APPSplitViewController: UISplitViewController, UISplitViewControllerDelegate {

    override func viewDidLoad() {

        super.viewDidLoad()
        preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
        maximumPrimaryColumnWidth = 32.0
        minimumPrimaryColumnWidth = 32.0
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

如何?

推荐答案

UISplitViewController仅在水平常规环境中使用show并排显示(新的TraitCollection大小)

UISplitViewController use show side-by-side only in horizontally regular environment (new TraitCollection size)

解决方案。
您必须更改SplitViewController的TraitCollection。怎么做:

Solution. You have to change TraitCollection of SplitViewController. How do this:


  • 创建一个ViewController并将你的SplitViewController作为一个孩子添加。

  • 覆盖traitCollection您的孩子的规则(UISplitViewController)

ViewController Wrapper

class TraitOverrideViewController: UIViewController {

 override func viewDidLoad() {
    super.viewDidLoad()
    configureSplitVC()
  }


  private func configureSplitVC() {

    let splitVC = self.childViewControllers[0] as UISplitViewController
    setOverrideTraitCollection(UITraitCollection(horizontalSizeClass: .Regular), forChildViewController: splitVC)
  }
}

在iOS 8中,UISplitViewController使用和TraitCollections来显示其内容。

它显示不同的风格取决于视图的大小和类型。您可以通过我在上面解释的技术进行更改。

您可以在WWDC视频中获得有关

In iOS 8 UISplitViewController uses Adaptive User Interfaces and TraitCollections to show its content.
It shows different style depending on the size of and type of the view. You can change by technic I explain above.
You can get more info in WWDC video about Building Adaptive Apps with UIKit

这篇关于iPhone上的UISplitViewController纵向始终显示iOS 8中的主图和细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 10:54