diff --git a/AMWaveTransition.podspec b/AMWaveTransition.podspec index 81c1f3c..79837c8 100644 --- a/AMWaveTransition.podspec +++ b/AMWaveTransition.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "AMWaveTransition" - s.version = "0.4" + s.version = "0.5" s.summary = "Custom transition between viewcontrollers holding tableviews. Each cell is animated to simulate a 'wave effect'." s.homepage = "https://github.com/andreamazz/AMWaveTransition" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Andrea Mazzini" => "andrea.mazzini@gmail.com" } - s.source = { :git => "https://github.com/andreamazz/AMWaveTransition.git", :tag => '0.4' } + s.source = { :git => "https://github.com/andreamazz/AMWaveTransition.git", :tag => '0.5' } s.platform = :ios, '7.0' s.source_files = 'AMWaveTransition', '*.{h,m}' s.requires_arc = true diff --git a/AMWaveTransition/AMWaveTransition.h b/AMWaveTransition/AMWaveTransition.h index 5eedb88..6a6e458 100644 --- a/AMWaveTransition/AMWaveTransition.h +++ b/AMWaveTransition/AMWaveTransition.h @@ -14,7 +14,8 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) { AMWaveTransitionTypeSubtle, - AMWaveTransitionTypeNervous + AMWaveTransitionTypeNervous, + AMWaveTransitionTypeBounce }; @interface AMWaveTransition : NSObject @@ -32,6 +33,15 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) { */ + (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation; +/** New transition + * + * Returns a AMWaveTransition instance. + * + * @param operation The UINavigationControllerOperation that determines the transition type (push or pop) + * @param type The transition type + */ ++ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type; + /** New transition * * Returns a AMWaveTransition instance. @@ -40,6 +50,15 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) { */ - (instancetype)initWithOperation:(UINavigationControllerOperation)operation; +/** New transition + * + * Returns a AMWaveTransition instance. + * + * @param operation The UINavigationControllerOperation that determines the transition type (push or pop) + * @param type The transition type + */ +- (instancetype)initWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type; + /** Attach the interactive gesture * * Attach the interactive gesture to the navigation controller. This will pop the current view controller when the user swipes from the left edge. diff --git a/AMWaveTransition/AMWaveTransition.m b/AMWaveTransition/AMWaveTransition.m index a95eefb..4e1f29b 100644 --- a/AMWaveTransition/AMWaveTransition.m +++ b/AMWaveTransition/AMWaveTransition.m @@ -33,21 +33,34 @@ - (instancetype)init self = [super init]; if (self) { [self setup]; + _operation = UINavigationControllerOperationNone; + _transitionType = AMWaveTransitionTypeNervous; } return self; } + (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation { - return [[self alloc] initWithOperation:operation]; + return [[self alloc] initWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous]; } - (instancetype)initWithOperation:(UINavigationControllerOperation)operation +{ + return [self initWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous]; +} + ++ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type +{ + return [[self alloc] initWithOperation:operation andTransitionType:type]; +} + +- (instancetype)initWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type { self = [super init]; if (self) { - _operation = operation; [self setup]; + _operation = operation; + _transitionType = type; } return self; } @@ -56,7 +69,6 @@ - (void)setup { _duration = DURATION; _maxDelay = MAX_DELAY; - _transitionType = AMWaveTransitionTypeNervous; } - (void)attachInteractiveGestureToNavigationController:(UINavigationController *)navigationController @@ -85,7 +97,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture // Starting controller UIViewController *fromVC; fromVC = (UIViewController *)self.navigationController.topViewController; - + // Controller that will be visible after the pop UIViewController *toVC; int index = (int)[self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController]; @@ -94,7 +106,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture // The gesture velocity will also determine the velocity of the cells float velocity = [gesture velocityInView:self.navigationController.view].x; CGPoint touch = [gesture locationInView:self.navigationController.view]; - + if (gesture.state == UIGestureRecognizerStateBegan) { [[fromVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { // The 'selected' cell will be the one leading the other cells @@ -109,7 +121,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture [self.attachmentsFrom addObject:attachment]; }]; - + // Kick the 'new' cells outside the view [[toVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { CGRect rect = view.frame; @@ -132,7 +144,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture [self.animator addBehavior:attachment]; [self.attachmentsTo addObject:attachment]; }]; - + } else if (gesture.state == UIGestureRecognizerStateChanged) { [[fromVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { @@ -143,7 +155,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture } [self.attachmentsFrom[idx] setAnchorPoint:(CGPoint){delta, [view.superview convertPoint:view.frame.origin toView:nil].y + view.frame.size.height / 2}]; }]; - + [[toVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { float delta = [gesture locationInView:self.navigationController.view].x - abs(self.selectionIndexTo - (int)idx) * velocity / 50; // Prevent the anchor point from going 'over' the cell @@ -158,7 +170,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture [self.animator removeBehavior:obj]; }]; [self.attachmentsFrom removeAllObjects]; - + [self.attachmentsTo enumerateObjectsUsingBlock:^(UIAttachmentBehavior *obj, NSUInteger idx, BOOL *stop) { [self.animator removeBehavior:obj]; }]; @@ -202,7 +214,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture }]; [toVC.view removeFromSuperview]; }]; - + } } } @@ -235,7 +247,7 @@ - (void)animateTransition:(id )transitionC if (self.operation == UINavigationControllerOperationPush) { delta = SCREEN_WIDTH; } else { - + delta = -SCREEN_WIDTH; } @@ -276,7 +288,7 @@ - (void)animateTransition:(id )transitionC // The controller has no table view, let's animate it gracefully [self hideView:fromVC.view withDelay:0 andDelta:-delta]; } - + if ([toVC respondsToSelector:@selector(visibleCells)]) { [[toVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) { NSTimeInterval delay = ((float)idx / (float)[[toVC visibleCells] count]) * self.maxDelay; @@ -299,8 +311,10 @@ - (void)hideView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(float) }; if (self.transitionType == AMWaveTransitionTypeSubtle) { [UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion]; - } else { + } else if (self.transitionType == AMWaveTransitionTypeNervous) { [UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion]; + } else if (self.transitionType == AMWaveTransitionTypeBounce){ + [UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:animation completion:completion]; } } @@ -313,8 +327,10 @@ - (void)presentView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(flo }; if (self.transitionType == AMWaveTransitionTypeSubtle) { [UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil]; - } else { + } else if (self.transitionType == AMWaveTransitionTypeNervous) { [UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil]; + } else if (self.transitionType == AMWaveTransitionTypeBounce){ + [UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:animation completion:nil]; } } diff --git a/AMWaveTransition/AMWaveViewController.m b/AMWaveTransition/AMWaveViewController.m index 26e8716..6acee6b 100644 --- a/AMWaveTransition/AMWaveViewController.m +++ b/AMWaveTransition/AMWaveViewController.m @@ -41,7 +41,7 @@ - (void)viewDidDisappear:(BOOL)animated toViewController:(UIViewController*)toVC { if (operation != UINavigationControllerOperationNone) { - return [AMWaveTransition transitionWithOperation:operation]; + return [AMWaveTransition transitionWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous]; } return nil; } diff --git a/Demo/Demo/ViewController.m b/Demo/Demo/ViewController.m index 31a9380..ca93c51 100644 --- a/Demo/Demo/ViewController.m +++ b/Demo/Demo/ViewController.m @@ -70,7 +70,7 @@ - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS toViewController:(UIViewController*)toVC { if (operation != UINavigationControllerOperationNone) { - return [AMWaveTransition transitionWithOperation:operation]; + return [AMWaveTransition transitionWithOperation:operation andTransitionType:AMWaveTransitionTypeBounce]; } return nil; }