Skip to content

Commit

Permalink
Merge pull request #18 from Raizlabs/develop
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
mr-fixit committed Nov 18, 2015
2 parents e92792f + dc0eb55 commit e501dbf
Show file tree
Hide file tree
Showing 36 changed files with 424 additions and 350 deletions.
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ UINavigationController *navigationController = [[UINavigationController alloc] i

- (void)viewDidLoad
{
[super viewDidLoad];
// Create the presentation interaction controller that allows a custom gesture
// to control presenting a new VC via a presentViewController
self.presentInteractionController = [[RZVerticalSwipeInteractionController alloc] init];
Expand All @@ -80,6 +81,7 @@ UINavigationController *navigationController = [[UINavigationController alloc] i

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Use the present interaction controller for presenting any view controller from this view controller
[[RZTransitionsManager shared] setInteractionController:self.presentInteractionController
fromViewController:[self class]
Expand All @@ -97,26 +99,22 @@ UINavigationController *navigationController = [[UINavigationController alloc] i

You can use any of the animation controllers or interaction controllers without the RZTransitionsManager and simply use them with the iOS7 custom View Controller transition APIs.

## Maintainers

[arrouse](https://github.com/arrouse) ([@arrouse88](http://twitter.com/arrouse88))

[nbonatsakis](https://github.com/nbonatsakis) ([@nickbona](http://twitter.com/nickbona))

[dostrander](https://github.com/dostrander) ([@_Derko](http://twitter.com/_Derko))

[markpragma](https://github.com/markpragma) ([@markpragma ](http://twitter.com/markpragma))

[rztakashi](https://github.com/rztakashi)

## Contributors

[smbarne](https://github.com/smbarne) ([@smbarne](http://twitter.com/smbarne))

## License
RZTransitions is distributed under an [MIT License](http://opensource.org/licenses/MIT). See the LICENSE file for more details.

```
Copyright (c) 2014 Raizlabs and other contributors
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.
```
RZTransitions is licensed under the MIT license. See the `LICENSE` file for details.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,3 @@
// The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ - (void)viewDidLoad

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// TODO: ** Cannot set the scroll view delegate and the collection view delegate at the same time **
// [self.presentOverscrollInteractor watchScrollView:self.collectionView];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ @implementation RZSimpleViewController

- (void)viewDidLoad
{
[super viewDidLoad];

// Create the push and pop interaction controller that allows a custom gesture
// to control pushing and popping from the navigation controller
self.pushPopInteractionController = [[RZHorizontalInteractionController alloc] init];
Expand Down Expand Up @@ -86,6 +88,7 @@ - (void)viewDidLoad

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[RZTransitionsManager shared] setInteractionController:self.presentInteractionController
fromViewController:[self class]
toViewController:nil
Expand Down
3 changes: 3 additions & 0 deletions RZTransitions/Data/RZTransitionAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

#define kRZTransitionActionCount 5

/**
* All the recognized transition action types.
*/
typedef NS_ENUM (NSInteger, RZTransitionAction) {
RZTransitionAction_Push = (1 << 0),
RZTransitionAction_Pop = (1 << 1),
Expand Down
9 changes: 9 additions & 0 deletions RZTransitions/Data/RZUniqueTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
*/
@property (assign, nonatomic) Class toViewControllerClass;

/**
* Creates a new @c RZUniqueTransition for use with the RZTransition Manager
*
* @param action The action that is to be used in the presentation/dismissal of the View controller
* @param fromViewController The ViewController class that will be going away.
* @param toViewController The ViewController class that will be presented.
*
* @return Instance of @c RZUniqueTransition
*/
- (instancetype)initWithAction:(RZTransitionAction)action
withFromViewControllerClass:(Class)fromViewController
withToViewControllerClass:(Class)toViewController;
Expand Down
4 changes: 2 additions & 2 deletions RZTransitions/Data/RZUniqueTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ - (instancetype)initWithAction:(RZTransitionAction)action
withToViewControllerClass:(Class)toViewController
{
self = [super init];
if (self) {
if ( self ) {
_transitionAction = action;
_fromViewControllerClass = fromViewController;
_toViewControllerClass = toViewController;
}
return self;
}

- (id)copyWithZone:(NSZone *)zone
- (instancetype)copyWithZone:(NSZone *)zone
{
RZUniqueTransition *copiedObject = [[[self class] allocWithZone:zone] init];

Expand Down
51 changes: 48 additions & 3 deletions RZTransitions/Interactors/RZBaseSwipeInteractionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,63 @@
//

#import <UIKit/UIKit.h>
#import <CoreGraphics/CGGeometry.h>

#import "RZTransitionInteractionControllerProtocol.h"

@interface RZBaseSwipeInteractionController : UIPercentDrivenInteractiveTransition
<RZTransitionInteractionController, UIGestureRecognizerDelegate>

@property (nonatomic, strong) UIViewController *fromViewController;
@property (nonatomic, strong) UIPanGestureRecognizer *gestureRecognizer;
@property (nonatomic, assign) BOOL reverseGestureDirection;
/**
* The ViewController that is doing the presenting.
*/
@property (strong, nonatomic) UIViewController *fromViewController;

/**
* The GestureRecognizer to get information about the swipe.
*/
@property (strong, nonatomic) UIPanGestureRecognizer *gestureRecognizer;

/**
* flag to know if the gesture is happening in the reverse direction.
*/
@property (assign, nonatomic) BOOL reverseGestureDirection;

/**
* Subclasses must overide this.
*
* @param panGestureRecognizer Pan gesture to check if the movement is positive.
*
* @return Flag if the gesture is in the positive or negative direction.
*/
- (BOOL)isGesturePositive:(UIPanGestureRecognizer *)panGestureRecognizer;

/**
* Subclass should overide this.
* The value that needs to be hit by the gesture recognizer to consider the transition happening.
*
* @return The percentage of the full amount that needs to be reached to complete the transition.
*/
- (CGFloat)swipeCompletionPercent;

/**
* Subclass must overide this.
* The translation percentage of the passed gesture recognizer
*
* @param panGestureRecognizer The Gesture recognizer being tested
*
* @return The percentage of the translation that is complete
*/
- (CGFloat)translationPercentageWithPanGestureRecongizer:(UIPanGestureRecognizer *)panGestureRecognizer;

/**
* Subclasses must override this.
* The physical translation that is on the the view due to the panGestureRecognizer
*
* @param panGestureRecognizer the gesture recognizer being tested
*
* @return the translation that is currently on the view.
*/
- (CGFloat)translationWithPanGestureRecongizer:(UIPanGestureRecognizer *)panGestureRecognizer;

@end
39 changes: 18 additions & 21 deletions RZTransitions/Interactors/RZBaseSwipeInteractionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ @implementation RZBaseSwipeInteractionController
@synthesize nextViewControllerDelegate = _delegate;
@synthesize shouldCompleteTransition = _shouldCompleteTransition;

- (id)init
- (instancetype)init
{
self = [super init];
if (self) {
if ( self ) {
_reverseGestureDirection = NO;
}
return self;
Expand All @@ -53,7 +53,8 @@ - (void)attachViewController:(UIViewController *)viewController withAction:(RZTr
[self attachGestureRecognizerToView:self.fromViewController.view];
}

- (void)attachGestureRecognizerToView:(UIView*)view {
- (void)attachGestureRecognizerToView:(UIView *)view
{
[view addGestureRecognizer:self.gestureRecognizer];
}

Expand All @@ -74,35 +75,33 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer
CGFloat percentage = [self translationPercentageWithPanGestureRecongizer:panGestureRecognizer];
BOOL positiveDirection = self.reverseGestureDirection ? ![self isGesturePositive:panGestureRecognizer] : [self isGesturePositive:panGestureRecognizer];

switch (panGestureRecognizer.state) {
switch ( panGestureRecognizer.state ) {
case UIGestureRecognizerStateBegan:
self.isInteractive = YES;

if (positiveDirection && self.nextViewControllerDelegate && [self.nextViewControllerDelegate conformsToProtocol:@protocol(RZTransitionInteractionControllerDelegate)])
{
if (self.action & RZTransitionAction_Push) {
if ( positiveDirection && self.nextViewControllerDelegate &&
[self.nextViewControllerDelegate conformsToProtocol:@protocol(RZTransitionInteractionControllerDelegate)] ) {
if ( self.action & RZTransitionAction_Push ) {
[self.fromViewController.navigationController pushViewController:[self.nextViewControllerDelegate nextViewControllerForInteractor:self] animated:YES];
}
else if (self.action & RZTransitionAction_Present) {
else if ( self.action & RZTransitionAction_Present ) {
// TODO: set and store a completion
[self.fromViewController presentViewController:[self.nextViewControllerDelegate nextViewControllerForInteractor:self] animated:YES completion:nil];
}
}
else
{
if (self.action & RZTransitionAction_Pop) {
else {
if ( self.action & RZTransitionAction_Pop ) {
[self.fromViewController.navigationController popViewControllerAnimated:YES];
}
else if (self.action & RZTransitionAction_Dismiss) {
else if ( self.action & RZTransitionAction_Dismiss ) {
[self.fromViewController dismissViewControllerAnimated:YES completion:nil];
}
}
break;

case UIGestureRecognizerStateChanged:
if (self.isInteractive)
{
self.shouldCompleteTransition = (percentage > [self swipeCompletionPercent]);
if ( self.isInteractive ) {
self.shouldCompleteTransition = ( percentage > [self swipeCompletionPercent] );
[self updateInteractiveTransition:percentage];
}
break;
Expand All @@ -113,10 +112,9 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer
break;

case UIGestureRecognizerStateEnded:
if (self.isInteractive)
{
if ( self.isInteractive ) {
self.isInteractive = NO;
if (!self.shouldCompleteTransition || panGestureRecognizer.state == UIGestureRecognizerStateCancelled) {
if ( !self.shouldCompleteTransition || panGestureRecognizer.state == UIGestureRecognizerStateCancelled ) {
[self cancelInteractiveTransition];
}
else {
Expand Down Expand Up @@ -157,10 +155,9 @@ - (CGFloat)translationWithPanGestureRecongizer:(UIPanGestureRecognizer *)panGest

#pragma mark - Overridden Properties

- (UIGestureRecognizer*)gestureRecognizer
- (UIGestureRecognizer *)gestureRecognizer
{
if (!_gestureRecognizer)
{
if ( !_gestureRecognizer ) {
_gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[_gestureRecognizer setDelegate:self];
}
Expand Down
4 changes: 2 additions & 2 deletions RZTransitions/Interactors/RZHorizontalInteractionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (CGFloat)swipeCompletionPercent

- (CGFloat)translationPercentageWithPanGestureRecongizer:(UIPanGestureRecognizer *)panGestureRecognizer
{
return fabsf([self translationWithPanGestureRecongizer:panGestureRecognizer] / panGestureRecognizer.view.bounds.size.width);
return fabs([self translationWithPanGestureRecongizer:panGestureRecognizer] / panGestureRecognizer.view.bounds.size.width);
}

- (CGFloat)translationWithPanGestureRecongizer:(UIPanGestureRecognizer *)panGestureRecognizer
Expand All @@ -57,7 +57,7 @@ - (CGFloat)translationWithPanGestureRecongizer:(UIPanGestureRecognizer *)panGest
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIPanGestureRecognizer *panGestureRecognizer = (UIPanGestureRecognizer*)gestureRecognizer;
UIPanGestureRecognizer *panGestureRecognizer = (UIPanGestureRecognizer *)gestureRecognizer;
CGFloat yTranslation = [panGestureRecognizer translationInView:panGestureRecognizer.view].y;
return yTranslation == 0;
}
Expand Down
20 changes: 18 additions & 2 deletions RZTransitions/Interactors/RZOverscrollInteractionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,30 @@
//

#import <UIKit/UIKit.h>
#import <CoreGraphics/CGGeometry.h>

#import "RZTransitionInteractionControllerProtocol.h"

@interface RZOverscrollInteractionController : UIPercentDrivenInteractiveTransition
<RZTransitionInteractionController, UIScrollViewDelegate>

@property(nonatomic, strong) UIViewController *fromViewController;
/**
* The View Controller that is being transitioned from.
*/
@property (strong, nonatomic) UIViewController *fromViewController;

/**
* The scrollview that is being watched to see if the overscroll is happening.
*
* @param scrollView the scrollview
*/
- (void)watchScrollView:(UIScrollView *)scrollView;

- (void)watchScrollView:(UIScrollView*)scrollView;
/**
* The percentage of the transition that is needed to complete
*
* @return 0 to 1 percentage.
*/
- (CGFloat)completionPercent;

@end
Loading

0 comments on commit e501dbf

Please sign in to comment.