Convert Figma logo to code with AI

John-Lluch logoSWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !

4,519
989
4,519
348

Top Related Projects

iOS 7/8 style side menu with parallax effect.

A lightweight, easy to use, Side Drawer Navigation Controller

PKRevealController is a delightful view controller container for iOS, enabling you to present multiple controllers on top of one another.

Customizable sliding view controller container.

iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.

Quick Overview

SWRevealViewController is a UIViewController subclass for implementing a slide-out sidebar menu in iOS applications. It provides a customizable and easy-to-use solution for creating a reveal view controller with support for both left and right side menus, gestures, and various configuration options.

Pros

  • Easy integration with existing iOS projects
  • Supports both left and right side menus
  • Customizable appearance and behavior
  • Gesture-based interactions for revealing menus

Cons

  • Limited documentation and examples
  • Not actively maintained (last update was in 2017)
  • May require additional work to adapt to modern iOS design patterns
  • Potential performance issues with complex view hierarchies

Code Examples

  1. Setting up the reveal view controller:
let frontViewController = UIViewController()
let rearViewController = UIViewController()
let revealViewController = SWRevealViewController(rearViewController: rearViewController, frontViewController: frontViewController)
  1. Adding a gesture recognizer to reveal the menu:
if let revealViewController = self.revealViewController() {
    view.addGestureRecognizer(revealViewController.panGestureRecognizer())
}
  1. Configuring reveal settings:
revealViewController.rearViewRevealWidth = 260
revealViewController.rightViewRevealWidth = 260
revealViewController.toggleAnimationType = .spring
revealViewController.toggleAnimationDuration = 0.3

Getting Started

  1. Install SWRevealViewController using CocoaPods: Add pod 'SWRevealViewController' to your Podfile and run pod install.

  2. Import the library in your view controller:

    import SWRevealViewController
    
  3. Set up the reveal view controller in your app delegate or initial view controller:

    let frontViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FrontViewController")
    let rearViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "RearViewController")
    let revealViewController = SWRevealViewController(rearViewController: rearViewController, frontViewController: frontViewController)
    window?.rootViewController = revealViewController
    window?.makeKeyAndVisible()
    
  4. Add gesture recognizers to your front view controller:

    if let revealViewController = self.revealViewController() {
        view.addGestureRecognizer(revealViewController.panGestureRecognizer())
        view.addGestureRecognizer(revealViewController.tapGestureRecognizer())
    }
    

Competitor Comparisons

iOS 7/8 style side menu with parallax effect.

Pros of RESideMenu

  • More customizable appearance with built-in options for background images and blur effects
  • Supports both left and right side menus simultaneously
  • Easier to implement with a simpler API and fewer configuration options required

Cons of RESideMenu

  • Less actively maintained, with fewer recent updates and contributions
  • Limited to a specific sliding menu style, whereas SWRevealViewController offers more flexibility in menu types
  • May have performance issues with complex view hierarchies due to its implementation approach

Code Comparison

RESideMenu:

RESideMenu *sideMenu = [[RESideMenu alloc] initWithContentViewController:contentViewController
                                                    leftMenuViewController:leftMenuViewController
                                                   rightMenuViewController:rightMenuViewController];
self.window.rootViewController = sideMenu;

SWRevealViewController:

SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];
self.window.rootViewController = revealController;
[revealController setRightViewController:rightViewController];

Both libraries offer easy-to-implement side menu solutions for iOS applications. RESideMenu provides a more visually customizable out-of-the-box experience, while SWRevealViewController offers greater flexibility in menu types and interactions. The choice between the two depends on specific project requirements and desired menu behavior.

A lightweight, easy to use, Side Drawer Navigation Controller

Pros of MMDrawerController

  • More customizable appearance and behavior options
  • Supports both left and right drawers simultaneously
  • Better performance with large view hierarchies

Cons of MMDrawerController

  • Less actively maintained (last update in 2017)
  • Steeper learning curve due to more complex API
  • Fewer built-in gesture recognizers

Code Comparison

MMDrawerController:

MMDrawerController *drawerController = [[MMDrawerController alloc]
    initWithCenterViewController:centerViewController
    leftDrawerViewController:leftDrawerViewController
    rightDrawerViewController:rightDrawerViewController];
[drawerController setMaximumLeftDrawerWidth:280.0];
[drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];

SWRevealViewController:

SWRevealViewController *revealViewController = [[SWRevealViewController alloc]
    initWithRearViewController:rearViewController
    frontViewController:frontViewController];
[revealViewController setRearViewRevealWidth:280.0];
[revealViewController panGestureRecognizer];

Both libraries offer similar functionality for creating drawer-style navigation in iOS apps. MMDrawerController provides more customization options and supports dual drawers, but has a steeper learning curve. SWRevealViewController is simpler to implement and more actively maintained, but offers fewer advanced features. The choice between them depends on the specific requirements of your project and your preference for simplicity versus flexibility.

PKRevealController is a delightful view controller container for iOS, enabling you to present multiple controllers on top of one another.

Pros of PKRevealController

  • More customizable with additional configuration options
  • Supports both left and right side panels simultaneously
  • Smoother animations and transitions

Cons of PKRevealController

  • Less actively maintained (last update was several years ago)
  • Fewer stars and forks on GitHub, indicating potentially less community support
  • More complex implementation due to additional features

Code Comparison

PKRevealController:

let frontViewController = UIViewController()
let leftViewController = UIViewController()
let rightViewController = UIViewController()

let revealController = PKRevealController(frontViewController: frontViewController, leftViewController: leftViewController, rightViewController: rightViewController)

SWRevealViewController:

let frontViewController = UIViewController()
let rearViewController = UIViewController()

let revealController = SWRevealViewController(rearViewController: rearViewController, frontViewController: frontViewController)

Both PKRevealController and SWRevealViewController are iOS libraries for implementing sliding menu interfaces. PKRevealController offers more flexibility with dual-side panels and extensive customization options, but it lacks recent updates. SWRevealViewController, while simpler, has better community support and more recent maintenance. The code comparison shows that PKRevealController allows for both left and right view controllers in its initialization, while SWRevealViewController focuses on a single rear view controller. Developers should consider their specific needs, desired customization level, and the importance of ongoing maintenance when choosing between these libraries.

Customizable sliding view controller container.

Pros of ECSlidingViewController

  • More customizable and flexible, allowing for various sliding styles and animations
  • Supports both left and right sliding menus out of the box
  • Easier to implement custom transitions and gestures

Cons of ECSlidingViewController

  • Less actively maintained, with fewer recent updates
  • May require more setup and configuration for basic functionality
  • Limited built-in support for additional features like parallax effects

Code Comparison

ECSlidingViewController:

let slidingViewController = ECSlidingViewController()
slidingViewController.topViewController = mainViewController
slidingViewController.underLeftViewController = menuViewController
slidingViewController.anchorRightRevealAmount = 250
self.window?.rootViewController = slidingViewController

SWRevealViewController:

let revealViewController = SWRevealViewController()
revealViewController.rearViewController = menuViewController
revealViewController.frontViewController = mainViewController
revealViewController.rearViewRevealWidth = 250
self.window?.rootViewController = revealViewController

Both libraries offer similar functionality for implementing sliding menus, but ECSlidingViewController provides more customization options at the cost of slightly more complex setup. SWRevealViewController is simpler to implement but may be less flexible for advanced use cases. The choice between the two depends on the specific requirements of your project and the level of customization needed.

iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.

Pros of SlideMenuControllerSwift

  • Written in Swift, making it more modern and compatible with newer iOS projects
  • Supports both left and right side menus out of the box
  • Offers customizable animation options for menu transitions

Cons of SlideMenuControllerSwift

  • Less mature and potentially less stable than SWRevealViewController
  • Fewer stars and forks on GitHub, indicating a smaller community and potentially less support
  • May have limited compatibility with older Objective-C projects

Code Comparison

SlideMenuControllerSwift:

let slideMenuController = SlideMenuController(mainViewController: mainViewController, leftMenuViewController: leftViewController, rightMenuViewController: rightViewController)

SWRevealViewController:

SWRevealViewController *revealViewController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];

Both libraries offer similar functionality for creating slide-out menus in iOS applications. SlideMenuControllerSwift is more suited for modern Swift projects, while SWRevealViewController has a longer history and may be more stable for Objective-C projects. The choice between the two depends on the specific project requirements, programming language preference, and desired customization options.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SWRevealViewController

A UIViewController subclass for revealing a rear (left and/or right) view controller behind a front controller, inspired by the Facebook app, done right!

NOTE ( Version 2.3)

  • This version fixes an old bug that caused an incorrect initialization of the class on particular scenarios.
  • The old RevealControllerStoryboardExample has been removed from the repo as it was deprecated, please use the newest RevealControllerStoryboardExample2 instead.

NOTE ( Upgrading to Version 2.1)

This version incorporates a new approach to Story Boards support.

  • There are now two different segue classes, SWRevealViewControllerSegueSetController and SWRevealViewControllerSeguePushController. The first one is meant to set the revealViewController with the initial controllers from the story board. The second one is used to push controllers to the front with animation. The former SWRevealViewControllerSegue still works but it has been deprecated.
  • A new StoryBoard example, RevealControllerStoryBoardExample2, has been added to demonstrate the use of the new segue classes. More responsability has been moved to the Story Board design while simplifying the SWRevealViewController implementation.

IMPORTANT NOTE: (Upgrading to Version 2.0)

A number of changes have been made on version 2.0 that may break your existing project. In case you are not ready to upgrade you can continue using previous versions. The last commit before 2.0.0 was tagged v1.1.3. The important changes that affect 2.0.0 are described next.

  • Dropped support for iOS6 and earlier. This version will only work on iOS7

  • The method setFrontViewController:animated: does no longer behave as previously. Particularly, it does not perform a full reveal animation. Instead it just replaces the frontViewController at its current position with optional animation. Use the new pushFrontViewController:animated: method as a replacement for your previous calls to setFrontViewController:animated:.

  • Added support for animated replacement of child controllers. The methods setRearViewController, setFrontViewController, setRightViewController now all have animated versions. The default animation is a Cross Dissolve effect. You can set the duration of the view controller replacement animation with replaceViewAnimationDuration

  • You can create custom viewController transition animations by providing an object implementing the UIViewControllerAnimatedTransitioning protocol.

  • Added the following new delegate methods

    - (void)revealController:(SWRevealViewController *)revealController willAddViewController:(UIViewController *)viewController forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated;
    - (void)revealController:(SWRevealViewController *)revealController didAddViewController:(UIViewController *)viewController forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated;
    - (id<UIViewControllerAnimatedTransitioning>)revealController:(SWRevealViewController *)revealController animationControllerForOperation:(SWRevealControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC;
  • The examples have been updated to demonstrate the new features. All animated calls to setFrontViewController:animated: have been replaced by calls to pushFrontViewController:animated:. The RevealControllerProject example implements a custom Animation Controller (UIViewControllerAnimatedTransitioning) to perform a slide up transition on replacement of the rightViewController. The RevealControllerProject3 example uses the default Cross Dissolve animation to set the Front Controller.

Features

  • A Reveal view controller implemented using view controller containment.
  • Support for custom viewController transition animations through UIViewControllerAnimatedTransitioning protocol
  • API easier than a UINavigationController.
  • Support for any combination of left/right rear controllers.
  • Correct handling of appearance methods on its child controllers that you can rely on.
  • Correct handling of rotations.
  • Can be embedded as a child view controller of other controllers or deployed as the rootViewController.
  • Plays nicely with any child view controllers or parent controllers.
  • Can be deployed as a child of itself to create cascade-like, hierarchical interfaces.
  • Seamless integration of pan gesture recognizer, behaving as smooth as silk.
  • A category method on UIViewController, revealViewController, to get the parent SWRevealViewController of any child controller, similar to the UIViewController's property navigationController.
  • Comprehensive set of delegate methods for getting full state of the controller and implementing your own code hooks for customizing behavior.
  • Lightweight, clean, easy-to-read, self-documenting code that you will enjoy using in your projects.

YouTube Video

http://youtu.be/8qYxGRJ3ZdA

Examples

The repo includes the following example projects that can be used as templates or for testing purposes

  • RevealControllerProject.xcodeproj
  • RevealControllerProject2.xcodeproj
  • RevealControllerProject3.xcodeproj
  • RevealControllerStoryboardExample.xcodeproj

Image                     Image

Requirements

  • iOS 7.0 or later.
  • ARC memory management.

Usage

The SWRevealViewController repository attempts to provide an updated cocoaPods file and consistent tag versioning, but it is not actively updated on the cocoapods-specs repository.

The easiest way to install it is by copying the following to your project:

  • SWRevealViewController.h
  • SWRevealViewController.m

On your project:

  • Initialize an instance of a SWRevealViewController passing in a "rear" and a "front" view controllers.
  • Optionaly add a "right" view controller or pass nil as the "rear" view controller.
  • Use the SWRevealViewController instance in your code as you would use any view controller.
  • Deploy as the application window rootViewController, or as a child of other containment controllers.
  • Get the panGestureRecognized and tapGestureRecognizer provided by the SWRevealViewController. You can leave them as they are for the default behavior or you can add them to a suitable view on your "front" view controller. For example add the panGestureRecognizer to a navigationBar on the viewDidLoad method of your front controller.
  • At any time, you can reveal, conceal the "rear" or "right" views or replace any of the view controllers, programmatically or based on user actions, with or without animations enabled

Basic API Description

Initializing a SWRevealViewController:

- (id)initWithRearViewController:(UIViewController *)rearViewController frontViewController:(UIViewController *)frontViewController;

Setting a right view controller:

@property (strong, nonatomic) UIViewController *rightViewController;

Animated setting of the front view controller:

- (void)pushFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated;

Animating the position of the front view controller. Position can be: FrontViewPositionLeftSideMostRemoved, FrontViewPositionLeftSideMost, FrontViewPositionLeftSide, FrontViewPositionLeft, FrontViewPositionRight, FrontViewPositionRightMost or FrontViewPositionRightMostRemoved

- (void)setFrontViewPosition:(FrontViewPosition)frontViewPosition animated:(BOOL)animated;

Creating and obtaining a pan gesture recognizer:

- (UIPanGestureRecognizer*)panGestureRecognizer;

Creating and obtaining a tap gesture recognizer:

- (UITapGestureRecognizer*)tapGestureRecognizer;

Other methods are documented in the SWRevealViewController.h header file.

Release Notes

As of November 15, 2013 Release Notes are updated on the class main header file. Please see SWRevealViewController.h

Tutorials

Xamarin Binding

Thanks to Jesper Vandborg for having contributed with a Xamarin Binding project for this controller that is available for download at https://github.com/Vandborg/SWRevealViewController-XamarinBinding.

Special Mentions

A Special Thank you to Joan Martin who formely worked at http://www.sweetwilliamsl.com and has recently been developing an app for http://www.citizen.tv. He had the original idea and implemented code for generic view deployment/undeployment and replacement of view controllers used in the class.

Early code and api was inspired on a similar class by Philip Kluz (Philip.Kluz@zuui.org)

License

Copyright (c) 2013 Joan Lluch joan.lluch@sweetwilliamsl.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.