我正在使用CosmicMaterial(http://www.cosmicmind.io/material)来实现Sidemenu或a.k.a抽屉菜单。我已经阅读了文档以及如何运行这个酷库的示例项目。我能够看到CosmicMaterial的Sidemenu的演示。
但有一个问题是我很难弄清楚如何在Sidemenu中嵌入导航控制器。
我在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
}
这是我在故事板中的布局。每个xib的所有id都已设置。
答案 0 :(得分:1)
之前我遇到过同样的问题。我只是发现我正在分配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的属性。并取消隐藏状态栏,否则在显示侧边菜单时您将遇到恼人的错误。
干杯!