gpt4 book ai didi

swift - iPhone 上纵向的 UISplitViewController 在 iOS 8 中始终显示主视图和细节

转载 作者:搜寻专家 更新时间:2023-10-31 19:31:33 25 4
gpt4 key购买 nike

iPhone 上 portrait 中的

UISplitViewControlleriOS 8 中始终显示 master 和 detail

我尝试继承 UISplitViewController 并将其配置为同时显示 master 和 detail。但没有任何影响。

class APPSplitViewController: UISplitViewController, UISplitViewControllerDelegate {

override func viewDidLoad() {

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

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

怎么做?

最佳答案

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

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。怎么做:

  • 创建一个 ViewController 并将您的 SplitViewController 添加为 subview 。
  • 为您的 child (UISplitViewController) 用 size.Regular 覆盖 traitCollection

ViewController 包装器

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 使用 Adaptive User Interfaces和 TraitCollections 以显示其内容。
它根据 View 的大小和类型显示不同的样式。您可以根据我上面解释的技术进行更改。
您可以在有关 Building Adaptive Apps with UIKit 的 WWDC 视频中获得更多信息

关于swift - iPhone 上纵向的 UISplitViewController 在 iOS 8 中始终显示主视图和细节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26670930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com