Skip to content

Commit

Permalink
Integrated changes from voznesenskym/AMWaveTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamazz committed May 29, 2014
1 parent 08e506c commit 5dfdd05
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
4 changes: 2 additions & 2 deletions AMWaveTransition.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
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
Expand Down
21 changes: 20 additions & 1 deletion AMWaveTransition/AMWaveTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

typedef NS_ENUM(NSInteger, AMWaveTransitionType) {
AMWaveTransitionTypeSubtle,
AMWaveTransitionTypeNervous
AMWaveTransitionTypeNervous,
AMWaveTransitionTypeBounce
};

@interface AMWaveTransition : NSObject <UIViewControllerAnimatedTransitioning>
Expand All @@ -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.
Expand All @@ -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.
Expand Down
44 changes: 30 additions & 14 deletions AMWaveTransition/AMWaveTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -56,7 +69,6 @@ - (void)setup
{
_duration = DURATION;
_maxDelay = MAX_DELAY;
_transitionType = AMWaveTransitionTypeNervous;
}

- (void)attachInteractiveGestureToNavigationController:(UINavigationController *)navigationController
Expand Down Expand Up @@ -85,7 +97,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
// Starting controller
UIViewController<AMWaveTransitioning> *fromVC;
fromVC = (UIViewController<AMWaveTransitioning> *)self.navigationController.topViewController;

// Controller that will be visible after the pop
UIViewController<AMWaveTransitioning> *toVC;
int index = (int)[self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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];
}];
Expand Down Expand Up @@ -202,7 +214,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
}];
[toVC.view removeFromSuperview];
}];

}
}
}
Expand Down Expand Up @@ -235,7 +247,7 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
if (self.operation == UINavigationControllerOperationPush) {
delta = SCREEN_WIDTH;
} else {

delta = -SCREEN_WIDTH;
}

Expand Down Expand Up @@ -276,7 +288,7 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)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;
Expand All @@ -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];
}
}

Expand All @@ -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];
}
}

Expand Down
2 changes: 1 addition & 1 deletion AMWaveTransition/AMWaveViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

1 comment on commit 5dfdd05

@superleexpert
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, ask a question, i used AMWaveTransition in my project, but i do not use storyboard, so after add AMWaveTransition, i tested and fournd the animation have a problem, when i push action, the from view's animation disappeared, inclued back view gesture, last i did not find a solution, can you help me or give me a suggestion?I do not know where modifications, ths very much.

Please sign in to comment.