在我的 UIKit 应用程序中,我使用 aUISplitViewController()
作为我的 rootViewController。我SceneDelegate
像这样配置它:
var splitView: UISplitViewController?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
self.makeSplitViewController()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = self.splitView
self.window = window
window.makeKeyAndVisible()
self.splitView?.viewController(for: .secondary)?.navigationController?.navigationBar.barStyle = .black
}
}
func makeSplitViewController() {
let splitViewController = UISplitViewController(style: .doubleColumn)
splitViewController.preferredDisplayMode = .oneBesideSecondary
let primaryViewController = UINavigationController(rootViewController: CalendarViewController())
let secondaryViewController = UIHostingController(rootView: EventDetailView())
splitViewController.setViewController(primaryViewController, for: .primary)
splitViewController.setViewController(secondaryViewController, for: .secondary)
splitViewController.setViewController(primaryViewController, for: .compact)
self.splitView = splitViewController
}
如您所见,我使用CalendarViewController
(包装在 UINavigationController 中)作为我的 primaryViewController,而对于辅助视图,我使用的是 SwiftUI 视图,包装在UIHostingController
结果如下所示:
如您所见,CalendarViewController 适合 iPhone 屏幕,但不适合 iPad 主列。来自CalendarKitCalendarViewController
,一个 Swift 日历库。
我需要在 CalendarViewController 中进行哪些更改以适应 SplitView 主列?有任何想法吗?