gpt4 book ai didi

swift - 使用侧边菜单 CosmicMaterial 时嵌入 NavigationController

转载 作者:行者123 更新时间:2023-11-28 06:42:44 25 4
gpt4 key购买 nike

我正在使用 CosmicMaterial ( http://www.cosmicmind.io/material ) 来实现侧边菜单或抽屉菜单。我已经阅读了文档以及如何运行这个很棒的库的示例项目。我能够看到 CosmicMaterial 的 Sidemenu 的演示。

但有一个问题是我很难弄清楚如何在 Sidemenu 中嵌入导航 Controller 。

我在 Appdelegate 中的代码 didFinishLaunchingWithOptions

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// Get view controllers from storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let homeTableViewController = storyboard.instantiateViewControllerWithIdentifier("HomeTableViewController") as! HomeTableViewController
let sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideTableViewController") as! SideTableViewController

// var navigationController = storyboard.instantiateViewControllerWithIdentifier("RootNavigationController") as! NavigationController
//
// var sideNavigationController = storyboard.instantiateViewControllerWithIdentifier("SideNavigationController") as! NavigationController
//
// navigationController = NavigationController(rootViewController: homeTableViewController)
// sideNavigationController = NavigationController(rootViewController: sideViewController)
//
//
// Configure the window with the SideNavigationController as the root view controller
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = SideNavigationController(rootViewController: homeTableViewController, leftViewController: sideViewController)
window?.makeKeyAndVisible()

return true
}

这是我在 Storyboard中的布局。每个xibs的所有id都已设置。

enter image description here

最佳答案

我之前遇到过同样的问题。我刚刚发现我分配的 navigonController 不正确。请参阅以下代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Get view controllers from storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootViewController = storyboard.instantiateViewControllerWithIdentifier("RootViewController") as! RootViewController
let sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideViewController") as! SideViewController

let navCon2 = NavigationController(rootViewController: sideViewController)
let navCon = NavigationController(rootViewController: rootViewController)

let sideNavigationController = SideNavigationController(rootViewController: navCon, leftViewController: navCon2)
sideNavigationController.enabledLeftTapGesture = true
sideNavigationController.enabledLeftPanGesture = true
sideNavigationController.enableHideStatusbar = false

// Configure the window with the SideNavigationController as the root view controller
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = sideNavigationController
window?.makeKeyAndVisible()
return true
}

请注意,您必须正确设置 SideNavigationController 的属性。并取消隐藏状态栏,否则在显示侧边菜单时您会遇到恼人的错误。

干杯!

关于swift - 使用侧边菜单 CosmicMaterial 时嵌入 NavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37494986/

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