Skip to content

carabina/SideMenuController

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SideMenuController

Purpose

SideMenuController is a custom container view controller written in Swift which will display the main content within a center panel and the secondary content (option menu, navigation menu, etc.) within a side panel when triggered. The side panel can be displayed either on the left or on the right side, under or above the center panel.

Example

Usage

  1. In the storyboard file, add one custom segue from the side menu controller to the center view controller. Don't forget to set its class to ContainmentSegue and its identifier to CenterContainment. NOTE: All future segues for changing the center controller will not require any identifier since the custom segue class defaults to CenterContainment when it has no identifier. Example

  2. In the storyboard file, add one custom segue from the side menu controller to the side view controller. Don't forget to set its class to ContainmentSegue and its identifier to SideContainment. Example

  3. In you AppDelegate file, in the application:didFinishLaunchingWithOptions: method you can customize the SideMenuController:

    You should customize at least these three properties :

SideMenuController.menuButtonImage = UIImage(named: "menuButton") SideMenuController.presentationStyle = .UnderCenterPanelLeft SideMenuController.animationStyle = .FadeAnimation ```

Customization

SideMenuController has the following customizable properties:

class var menuButtonImage : UIImage?

The image object to be displayed on the button that will trigger the side panel. Button displayed either on the right or left side of the navigation bar.

class var panningEnabled : Bool

A boolean flag indicating wether or not panning is enabled for revealing/hiding the side panel.

class var presentationStyle : SideMenuControllerPresentationStyle

The presentation style of the side menu controller.

class var animationStyle : CenterContainmentAnimationStyle

The animation style for changin the center view controller.

class var useShadow: Bool

A flag indicating wether or not the center panel should draw shadow around it.

Supported OS & SDK Versions

  • Supported build target - iOS 7.0 (Xcode 6.x)

Custom types

enum SideMenuControllerPresentationStyle {
    case UnderCenterPanelLeft
    case UnderCenterPanelRight
    case AboveCenterPanelLeft
    case AboveCenterPanelRight
}

This enum exposes the four different presentation styles for the side menu controller. Default value is UnderCenterPanelLeft.

enum CenterContainmentAnimationStyle {
    case CircleMaskAnimation
    case FadeAnimation
}

This enum exposes the two different animation styles for the change of the center view controller. Default value is CircleMaskAnimation.

  class ContainmentSegue : UIStoryboardSegue

A custom UIStoryboardSegue subclass which makes this component work seamlessly with storyboards.

  enum ContainmentSegueType{
    case Center
    case Side
}

This enum exposes the two types of the containment segue: for adding a new center view controller, or for adding a new side view controller.

Methods

SideMenuController implements an extension for the UIViewController which exposes the method:

func sideMenuController() 

This method goes up the parent view controller chain and searches for the SideMenuController. You can use this method if you want to get a reference to the SideMenuController from within your custom view controller.

func addNewController(controller : UIViewController, forSegueType type:ContainmentSegueType)

This method gets called when the ContainmentSegue gets performed. Normally you don't have to call this method yourself since it will get called automatically when the segue is performed. If you don't use storyboards or segues, you can use this method to add the center and side controllers.

func toggleSidePanel ()

This method gets called when the menu button in the navigation bar is pressed. You can call this method yourself from your view controller by using self.sideMenuController()?.toggleSidePanel() if you want to trigger the side pannel programmatically.

About

A side menu controller written in Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%