Awesome
KVRootBaseSideMenu-Swift
It's a root base side menu with autolayout for iOS applications & It is also written in pure swift.
Demo
Features
- Highly customizable & easy to use.
- You can add this side menu in a view of viewCintroller Or any specific subview of viewcontroller.
- Support both left & right side menu.
- Support finger touch to open or close both side menu
- Automatic orientation support because of autolayout that we used.
- Automatically manage Left, right or left & right side menu sliding & toggle functionality to open or close.
- Complete example
- Carthage Support
TO DO
- By supporting @IBInspectable, the class properties can be exposed in the Interface Builder
- Advance example.
Requirements
- iOS 8+ (compatible with iOS 8)
- Xcode 8.0
<a name="usage"> Usage </a>
Step 1.
Prepare SideMenuViewController
, either LeftViewController
or RightViewController
or both.
- Create a subclass of KVRootBaseSideMenuViewController called SideMenuViewController.
- Create LeftViewController Or RightViewController Or both class subclassing from UIViewController.
class SideMenuViewController: KVRootBaseSideMenuViewController {
}
class LeftViewController: UIViewController {
}
class RightViewController: UIViewController {
}
- In Storyboard, Drag three view controllers from the Object library to the storyboard canvas and give them class name in the Attributes inspector for the scenes. one is
SideMenuViewController
second isLeftViewController
& third isRightViewController
.
Step 2.
-
Prepare roots(options available in left and/or Right side menu) & roots identifiers and Connect all the roots from side menu view controller.
-
In storyboard, drag view controller objects from the Object library to the scene, create a custom view controller class. Specify this class as the custom class in the Attributes inspector for the scene.
-
Now define the roots Identifier, in this example I'm doing as -
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>
- You need to create a segue from the
SideMenuViewController
itself to the destination root viewController. You must do this for each root viewController and give them appropriateidentifiers
and give them ’Segue Class’ i.e.KVCustomSegue
Step 3.
- To enable left or right or both SideMenu, you must assign a
leftSideMenuViewController
orrightSideMenuViewController
or both at any moment. In this example I'm doing as -
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