Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Lluch committed Mar 9, 2014
1 parent 20f8383 commit b669863
Show file tree
Hide file tree
Showing 17 changed files with 553 additions and 123 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@

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

## IMPORTANT NOTE: Upgrading to SWRevealViewController version 2.0

* 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 of your previous `setFrontViewController:animated:` calls.

* 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 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 of setFrontViewController:animated: have been replaced by pushFrontViewController:animated:
The RevealControllerProject example implements a custom Animation Controller performing a slide up transition on 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.
Expand All @@ -14,17 +38,17 @@ A UIViewController subclass for revealing a rear (left and/or right) view contro
* 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.

## Examples

![Dynamic](https://raw.github.com/John-Lluch/SWRevealViewController/master/SWRevealViewController3.png)
![Dynamic](https://raw.github.com/John-Lluch/SWRevealViewController/master/SWRevealViewController.png)


## Requirements

* iOS 5.1 through iOS 7.0 or later.
* iOS 7.0 or later.
* ARC memory management.

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
4E19D77818CB6FC100795A13 /* CustomAnimationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E19D77718CB6FC100795A13 /* CustomAnimationController.m */; };
4ECAAEE5169049A1005862CE /* MapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ECAAEE4169049A1005862CE /* MapViewController.m */; };
4ECAAEE9169049AD005862CE /* RearViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ECAAEE8169049AD005862CE /* RearViewController.m */; };
4ECAAEEC169049B7005862CE /* FrontViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ECAAEEB169049B7005862CE /* FrontViewController.m */; };
Expand All @@ -29,6 +30,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
4E19D77618CB6FC100795A13 /* CustomAnimationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomAnimationController.h; sourceTree = "<group>"; };
4E19D77718CB6FC100795A13 /* CustomAnimationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomAnimationController.m; sourceTree = "<group>"; };
4ECAAEE3169049A1005862CE /* MapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewController.h; sourceTree = "<group>"; };
4ECAAEE4169049A1005862CE /* MapViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewController.m; sourceTree = "<group>"; };
4ECAAEE7169049AD005862CE /* RearViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RearViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,6 +95,15 @@
name = "Supporting Files";
sourceTree = "<group>";
};
4E19D77518CB6F1900795A13 /* Animation Controllers */ = {
isa = PBXGroup;
children = (
4E19D77618CB6FC100795A13 /* CustomAnimationController.h */,
4E19D77718CB6FC100795A13 /* CustomAnimationController.m */,
);
name = "Animation Controllers";
sourceTree = "<group>";
};
4ECAAEED16904A0F005862CE /* Resources */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -175,6 +187,7 @@
children = (
5E605BB814A081F900853025 /* AppDelegate.h */,
4EDE1D02168F0648005656D1 /* AppDelegate.m */,
4E19D77518CB6F1900795A13 /* Animation Controllers */,
5E5A2CF414E0CB860042AE1E /* RearViewController (Rear) */,
4EE05DEC16BE63ED0046E135 /* RightViewController */,
5E5A2CF314E0CB760042AE1E /* FrontViewController (Front) */,
Expand Down Expand Up @@ -268,6 +281,7 @@
4EDE1D03168F0648005656D1 /* AppDelegate.m in Sources */,
4EDE1D0C168F06A5005656D1 /* SWRevealViewController.m in Sources */,
4EDE1D11168F06E3005656D1 /* main.m in Sources */,
4E19D77818CB6FC100795A13 /* CustomAnimationController.m in Sources */,
4ECAAEE5169049A1005862CE /* MapViewController.m in Sources */,
4ECAAEE9169049AD005862CE /* RearViewController.m in Sources */,
4ECAAEEC169049B7005862CE /* FrontViewController.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions RevealControllerExample/RevealControllerProject/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Early code inspired on a similar class by Philip Kluz ([email protected])
*/

#import <UIKit/UIKit.h>
Expand Down
73 changes: 44 additions & 29 deletions RevealControllerExample/RevealControllerProject/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
/*
Copyright (c) 2011, Philip Kluz ([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
/*
Copyright (c) 2013 Joan Lluch <[email protected]>
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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:
* Neither the name of Philip Kluz, 'zuui.org' nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL PHILIP KLUZ BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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.
Early code inspired on a similar class by Philip Kluz ([email protected])
*/
*/


#import "AppDelegate.h"

#import "SWRevealViewController.h"
#import "FrontViewController.h"
#import "RearViewController.h"
#import "RightViewController.h"
#import "CustomAnimationController.h"

@interface AppDelegate()<SWRevealViewControllerDelegate>
@end
Expand Down Expand Up @@ -75,7 +71,27 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

#define LogDelegates 1
#pragma mark - SWRevealViewDelegate

- (id <UIViewControllerAnimatedTransitioning>)revealController:(SWRevealViewController *)revealController animationControllerForOperation:(SWRevealControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
if ( operation != SWRevealControllerOperationReplaceRightController )
return nil;

if ( [toVC isKindOfClass:[RightViewController class]] )
{
if ( [(RightViewController*)toVC wantsCustomAnimation] )
{
id<UIViewControllerAnimatedTransitioning> animationController = [[CustomAnimationController alloc] init];
return animationController;
}
}

return nil;
}


#define LogDelegates 0

#if LogDelegates
- (NSString*)stringFromFrontViewPosition:(FrontViewPosition)position
Expand All @@ -91,7 +107,6 @@ - (NSString*)stringFromFrontViewPosition:(FrontViewPosition)position
return str;
}


- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
NSLog( @"%@: %@", NSStringFromSelector(_cmd), [self stringFromFrontViewPosition:position]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright (c) 2013 Joan Lluch <[email protected]>
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.
*/

#import <Foundation/Foundation.h>

@interface CustomAnimationController : NSObject<UIViewControllerAnimatedTransitioning>

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright (c) 2013 Joan Lluch <[email protected]>
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.
*/

#import "CustomAnimationController.h"


#define TRANSITION_DURATION 0.5

@implementation CustomAnimationController

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return TRANSITION_DURATION;
}


- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

UIView *fromView = fromViewController.view;
UIView *toView = toViewController.view;

CGRect initialFromViewFrame = [transitionContext initialFrameForViewController:fromViewController];
CGRect finalFromViewFrame = initialFromViewFrame;
finalFromViewFrame.origin.y -= initialFromViewFrame.size.height;

CGRect finalToViewFrame = [transitionContext finalFrameForViewController:toViewController];
CGRect initialToViewFrame = finalToViewFrame;
initialToViewFrame.origin.y += finalToViewFrame.size.height;

fromView.frame = initialFromViewFrame;
toView.frame = initialToViewFrame;

[UIView animateWithDuration:TRANSITION_DURATION
animations:^ { fromView.frame = finalFromViewFrame; toView.frame = finalToViewFrame;}
completion:^(BOOL finished) { [transitionContext completeTransition:finished]; }];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
{
FrontViewController *frontViewController = [[FrontViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
[revealController setFrontViewController:navigationController animated:YES];
[revealController pushFrontViewController:navigationController animated:YES];
}
// Seems the user attempts to 'switch' to exactly the same controller he came from!
else
Expand All @@ -124,7 +124,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
{
MapViewController *mapViewController = [[MapViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mapViewController];
[revealController setFrontViewController:navigationController animated:YES];
[revealController pushFrontViewController:navigationController animated:YES];
}

// Seems the user attempts to 'switch' to exactly the same controller he came from!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@

@interface RightViewController : UIViewController

@property (nonatomic) BOOL wantsCustomAnimation;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
@interface RightViewController ()
// Private Methods:
- (IBAction)replaceMe:(id)sender;
- (IBAction)replaceMeCustom:(id)sender;
- (IBAction)toggleFront:(id)sender;
@end

Expand Down Expand Up @@ -80,7 +81,14 @@ - (BOOL)prefersStatusBarHidden
- (IBAction)replaceMe:(id)sender
{
RightViewController *replacement = [[RightViewController alloc] init];
[self.revealViewController setRightViewController:replacement];
[self.revealViewController setRightViewController:replacement animated:YES];
}

- (IBAction)replaceMeCustom:(id)sender
{
RightViewController *replacement = [[RightViewController alloc] init];
replacement.wantsCustomAnimation = YES;
[self.revealViewController setRightViewController:replacement animated:YES];
}


Expand All @@ -89,19 +97,10 @@ - (IBAction)toggleFront:(id)sender
MapViewController *mapViewController = [[MapViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mapViewController];

[self.revealViewController setFrontViewController:navigationController animated:YES];

// This is what was required Before v1.0.9 (Now it was commented out)
//
// SWRevealViewController *revealController = self.revealViewController;
// [revealController setFrontViewPosition:FrontViewPositionLeftSideMost animated:YES];
// [revealController setFrontViewController:navigationController];
// [revealController setFrontViewPosition:FrontViewPositionLeft animated:YES];
[self.revealViewController pushFrontViewController:navigationController animated:YES];
}




//- (void)dealloc
//{
// NSLog(@"RightController dealloc");
Expand Down
Loading

0 comments on commit b669863

Please sign in to comment.