Home

Awesome

KVRootBaseSideMenu-Swift

It's a root base side menu with autolayout for iOS applications & It is also written in pure swift.

Demo

KVRootBaseSideMenu-Swift

Features

TO DO

Requirements

<a name="usage"> Usage </a>

Step 1.

Prepare SideMenuViewController, either LeftViewController or RightViewController or both.

class SideMenuViewController: KVRootBaseSideMenuViewController {

}
class LeftViewController: UIViewController {

}
class RightViewController: UIViewController {

}

Step 2.

public extension KVSideMenu
{
    // Here define the roots identifier of side menus that must be connected
    // from KVRootBaseSideMenuViewController or any derived class of it
    // In Storyboard using KVCustomSegue
    
    static public let leftSideViewController   =  "LeftSideViewController"
    static public let rightSideViewController  =  "RightSideViewController"
    
    struct RootsIdentifiers
    {
        static public let initialViewController  =  "SecondViewController"

        // All roots viewcontrollers
        static public let firstViewController    =  "FirstViewController"
        static public let secondViewController   =  "SecondViewController"
    }
    
}

<a name="Connect_Roots"> How to connect roots from side menu view controller </a>

Step 3.

class SideMenuViewController: KVRootBaseSideMenuViewController
{
    override func viewDidLoad() {
      super.viewDidLoad()
        
      // Configure The Side Menu
      leftSideMenuViewController  =  self.storyboard?.instantiateViewControllerWithIdentifier(KVSideMenu.leftSideViewController)
      rightSideMenuViewController =  self.storyboard?.instantiateViewControllerWithIdentifier(KVSideMenu.rightSideViewController)

      // Set default root
      self.changeSideMenuViewControllerRoot(KVSideMenu.RootsIdentifiers.initialViewController)
    }

}

Now side menu setup is done.

To Change Root call -

public func changeSideMenuViewControllerRoot(rootIdentifier:String)

To Toggle Side Menu Post notification

Post notification by name KVSideMenu.Notifications.toggleRight Or KVSideMenu.Notifications.toggleLeft

Ex-

class LeftSideViewController: UIViewController
{
    @IBAction func moveToFirstViewControllerButton(sender: AnyObject) {
        self.changeSideMenuViewControllerRoot(KVSideMenu.RootsIdentifiers.firstViewController)
        NSNotificationCenter.defaultCenter().postNotificationName(KVSideMenu.Notifications.toggleLeft, object: self)
    }
    
    @IBAction func moveToSecondViewControllerButton(sender: AnyObject) {
        self.changeSideMenuViewControllerRoot(KVSideMenu.RootsIdentifiers.secondViewController)
        NSNotificationCenter.defaultCenter().postNotificationName(KVSideMenu.Notifications.toggleLeft, object: self)
    }

}

class RightSideViewController: UIViewController 
{
    @IBAction func moveToFirstViewControllerButton(sender: AnyObject) {
        self.changeSideMenuViewControllerRoot(KVSideMenu.RootsIdentifiers.firstViewController)
        NSNotificationCenter.defaultCenter().postNotificationName(KVSideMenu.Notifications.toggleRight, object: nil)
    }
    
    @IBAction func moveToSecondViewControllerButton(sender: AnyObject) {
        self.changeSideMenuViewControllerRoot(KVSideMenu.RootsIdentifiers.secondViewController)
        NSNotificationCenter.defaultCenter().postNotificationName(KVSideMenu.Notifications.toggleRight, object: nil)
    }

}

License

KVRootBaseSideMenu-Swift is released under the MIT license. See the LICENSE for details.

Contributions

Any contribution is more than welcome! You can contribute through pull requests and issues on GitHub.

Author

Keshav Vishwkarma, If you wish to contact me, email at: keshavvbe@gmail.com