A UIViewController subclass for revealing a rear (left and/or right) view controller behind a front controller, inspired by the Facebook app, done right!
This version incorporates a new approach to Story Boards support.
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
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
Added support for animated replacement of child controllers. The methods
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
You can create custom viewController transition animations by providing an object implementing the
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;
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.
revealViewController, to get the parent
SWRevealViewControllerof any child controller, similar to the UIViewController's property
The repo includes the following example projects that can be used as templates or for testing purposes
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:
On your project:
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:
- (void)setFrontViewPosition:(FrontViewPosition)frontViewPosition animated:(BOOL)animated;
Creating and obtaining a pan gesture recognizer:
Creating and obtaining a tap gesture recognizer:
Other methods are documented in the SWRevealViewController.h header file.
As of November 15, 2013 Release Notes are updated on the class main header file. Please see
Some time ago the guys at AppCoda published an online tutorial featuring the SWRevealViewController: "How To Add a Slide-out Sidebar Menu in Your Apps" (thanks for that). You will find it at http://www.appcoda.com/ios-programming-sidebar-navigation-menu/ . They have recently updated it to match the lastest SWRevealViewController version. Worth a read.
Tammy Coron on Ray Wenderlich blog made an excelent tutorial on "how to build a slide-out navigation panel". She recomends the SWRevealViewController in case you do not want to implement one yourself. http://www.raywenderlich.com/32054/how-to-create-a-slide-out-navigation-like-facebook-and-path
You can also check "Drawer View iOS App with SWRevealViewController" at http://bcdilumonline.blogspot.com.es/2014/03/drawer-view-ios-app-with.html for step by step instructions on how to install and use the controller. Worth a read for those who do not quite feel at home with storyboards :-)
I also found this one in Spanish "Sidebar o menú lateral mediante SWRevealViewController" by wikimovil.es at http://wikimovil.es/sidebar-o-menu-lateral-mediante-swrevealviewcontroller-parte-1/ which is doing a good job with detailed explanations on how to implement it using Story Boards (before V2.1)
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.
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)
Copyright (c) 2013 Joan Lluch firstname.lastname@example.org
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.