I've been trying to make a left slide-out menu for a couple of days. I couldn't get any of the libraries to work with my application, so I resorted to raywenderlich's tutorial:
http://www.raywenderlich.com/78568/create-slide-out-navigation-panel-swift
However, it doesn't do exactly what I want. My main problem is that when I slide out the menu the navigation bar slides out with it. I need my navigation bar to stay where it is and only move the content underneath it.
I tried "self.view.bringSubviewToFront(navigationController.navigationBar)" But that didn't work.
Here's a screenshot of what I'm trying to accomplish.
My current setup is made using a ContainerViewController
that's set in my appDelegate's
didFinishLaunchingWithOptions`:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let containerViewController = ContainerViewController()
window!.rootViewController = containerViewController
window!.makeKeyAndVisible()
return true
This ContainerViewController is getting 2 childViewControllers.
the CenterViewControllerController (my content)
The CenterViewController will have the navigationController correctly set up.
var centerNavigationController: NavigationController!
var centerViewController: CenterViewController!
In the ContainerViewController
viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
centerViewController = UIStoryboard.centerViewController()
centerViewController.delegate = self
// wrap the centerViewController in a navigation controller, so we can push views to it
// and display bar button items in the navigation bar
centerNavigationController = NavigationController(rootViewController: LandingPageVC())
view.addSubview(centerNavigationController.view)
addChildViewController(centerNavigationController)
centerNavigationController.didMoveToParentViewController(self)
let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")
centerNavigationController.view.addGestureRecognizer(panGestureRecognizer)
}
and the SidePanelViewController (my menu & the problematic one.)
var leftViewController: SidePanelViewController?
func addLeftPanelViewController() {
if (leftViewController == nil) {
leftViewController = SidePanelViewController()
addChildSidePanelController(leftViewController!)
}
}
func addChildSidePanelController(sidePanelController: SidePanelViewController) {
println("addChildSidePanelController")
view.insertSubview(sidePanelController.view, atIndex: 0)
addChildViewController(sidePanelController)
sidePanelController.didMoveToParentViewController(self)
}
The SidePanelViewController
currently doesn't have a navigationController. I did try adding it. But that did not have the desired results.
Based on the comments, what I need to do is somehow making the ContainerViewController the one that has a navigationController, so both of it's childControllers should have that as well? However I have no clue how I would go about adding the navigationController on that level.
Any help would be greatly appreciated! (I'm not using storyboards)
Libraries I tried:
ENSwiftSideMenu (did what I want. But spent 2 days trying to make it work with no results)
Brian Advent youtube tutorial
Dekatotoro's SlideMenuControllerSwift
wanaya/Slide-Menu
SWRevealViewController in Swift