iPhone上的UISplitViewController纵向始终显示iOS 8中的主图和细节 [英] UISplitViewController in portrait on iPhone always show master and detail in 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)
拆分视图控制器根据可用空间确定其子视图控制器的排列。在水平常规环境中,分割视图控制器尽可能并排显示其视图控制器。在水平紧凑的环境中,分割视图控制器更像是导航控制器,最初显示主视图控制器并根据需要推送或弹出辅助视图控制器。您还可以通过为 preferredDisplayMode property。
The split view controller determines the arrangement of its child view controllers based on the available space. In a horizontally regular environment, the split view controller presents its view controllers side-by-side whenever possible. In a horizontally compact environment, the split view controller acts more like a navigation controller, displaying the primary view controller initially and pushing or popping the secondary view controller as needed. You can also ask the split view controller to prefer a specific arrangement by assigning a value to the preferredDisplayMode property.
解决方案。
您必须更改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视频中获得有关使用UIKit构建自适应应用程序
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中的主图和细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!