提问人:Sam Stone 提问时间:10/20/2023 更新时间:10/20/2023 访问量:18
UITabBarController 作为 UISplitViewController 中的辅助控制器,在紧凑视图中生成 2 个导航栏
UITabBarController as secondary controller in UISplitViewController is producing 2 navigation bars in compact view
问:
这有点奇怪,但是当使用 UIKit 时(我已经在 SwiftUI 中尝试过,并且没有发生相同的结果),并尝试将 a 作为辅助项放在 ,辅助视图控制器上会显示一个额外的内容,但只有在以紧凑的形式查看时才会显示。选择另一个选项卡并重新访问该视图可解决问题。下面是一些图像 - 直接屏幕截图和视图调试器中的图像:UITabViewController
UISplitViewController
UINavigationBar
iPhone上的问题图像 显示两个选项卡栏的视图调试器的图像
这是我的代码,我已经把它从一个更大的项目中提取出来,但它仍然是可重现的:
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else { return }
let splitViewController = UISplitViewController(style: .doubleColumn)
let primaryVc = UINavigationController(rootViewController: PrimaryTestUIViewController())
let tabBar = UITabBarController()
tabBar.viewControllers = [UINavigationController(rootViewController: SecondaryTestUIViewController()),
UINavigationController(rootViewController: SecondaryTestUIViewController()),
UINavigationController(rootViewController: SecondaryTestUIViewController())]
let secondaryVC = tabBar
splitViewController.viewControllers = [primaryVc, secondaryVC]
let window = UIWindow(windowScene: windowScene)
window.rootViewController = splitViewController
self.window = window
window.makeKeyAndVisible()
}
}
class PrimaryTestUIViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Primary view"
}
}
class SecondaryTestUIViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Secondary view"
}
}
答: 暂无答案
评论