Sliding Menu
This is an example of simple Sliding Navigation Menu build without using an external library.
In the Storyboard add a UIViewController that holds two Container Views:
UITableViewController for the Menu options - 80% of the screen width and
Tab Bar Controller that holds the selected menu details - 20% of the screen width (the tab bar is hidden)
two swipe gesture recognizers (left and right)
an outlet for the constraint between the left edge of the left container view and the UIViewController
In the UIViewController:
@IBOutlet weak var leftCon: NSLayoutConstraint! @IBOutlet weak var leftContainer: UIView! override func viewDidLoad() { // Add notification for handle the menu selection NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("updareConst:"), name: "updateConstraints", object: nil) } override func viewDidAppear(animated: Bool) { // present the first view controller full screen leftCon.constant = -leftContainer.frame.size.width } // Add actions for swipe gesture recognizers @IBAction func closeMenu(sender: UISwipeGestureRecognizer) { leftCon.constant = -leftContainer.frame.size.width-16 UIView.animateWithDuration(0.3){ self.view.layoutIfNeeded() } } @IBAction func openMenu(sender: UISwipeGestureRecognizer) { leftCon.constant = 0 UIView.animateWithDuration(0.3) { self.view.layoutIfNeeded() } } func updareConst(notification: NSNotification){ leftCon.constant = -leftContainer.frame.size.width - 16 UIView.animateWithDuration(0.3) { self.view.layoutIfNeeded() } }
In the UITableViewController:
// Select the first tab var tbc: UITabBarController! override func viewDidAppear(animated: Bool) { tbc = self.parentViewController!.childViewControllers[1] as! UITabBarController } // Handle row selection override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { tbc.selectedIndex = indexPath.row NSNotificationCenter.defaultCenter().postNotificationName("updateConstraints", object: nil) }
First selected View Controller:
// Hide tab bar override func viewDidLoad() { self.tabBarController?.tabBar.hidden = true }
You can find more on this topic here: http://stackoverflow.com/questions/29425646/swift-slide-out-menu-without-sliding-the-navigationbar-programatically














