Skip to content

Commit a2c9422

Browse files
committed
Fix animation
1 parent e569c50 commit a2c9422

File tree

1 file changed

+63
-64
lines changed

1 file changed

+63
-64
lines changed

Source/AMWaveTransition.m

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -373,81 +373,80 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
373373
toVC.view.frame = [transitionContext finalFrameForViewController:toVC];
374374
// And kick it aside
375375
toVC.view.transform = CGAffineTransformMakeTranslation(delta, 0);
376-
376+
377377
[transitionContext containerView].backgroundColor = fromVC.view.backgroundColor;
378-
379-
// First step is required to trigger the load of the visible cells.
380-
[UIView animateWithDuration:0 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{} completion:^(BOOL finished) {
381-
382-
// Plain animation that moves the destination controller in place. Once it's done it will notify the transition context
383-
if (self.operation == UINavigationControllerOperationPush) {
384-
[toVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
385-
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
386-
[toVC.view setTransform:CGAffineTransformIdentity];
387-
} completion:^(BOOL finished2) {
388-
[transitionContext completeTransition:YES];
389-
}];
390-
} else {
391-
[fromVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
378+
379+
// Trigger the layout of the new cells
380+
[[transitionContext containerView] layoutIfNeeded];
381+
382+
// Plain animation that moves the destination controller in place. Once it's done it will notify the transition context
383+
if (self.operation == UINavigationControllerOperationPush) {
384+
[toVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
385+
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
392386
[toVC.view setTransform:CGAffineTransformIdentity];
393-
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
394-
[fromVC.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
395-
} completion:^(BOOL finished2) {
396-
[fromVC.view removeFromSuperview];
397-
[transitionContext completeTransition:YES];
398-
}];
399-
}
400-
401-
NSArray *fromViews = [self visibleCellsForViewController:fromVC];
402-
NSArray *toViews = [self visibleCellsForViewController:toVC];
387+
} completion:^(BOOL finished2) {
388+
[transitionContext completeTransition:YES];
389+
}];
390+
} else {
391+
[fromVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
392+
[toVC.view setTransform:CGAffineTransformIdentity];
393+
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
394+
[fromVC.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
395+
} completion:^(BOOL finished2) {
396+
[fromVC.view removeFromSuperview];
397+
[transitionContext completeTransition:YES];
398+
}];
399+
}
403400

404-
__block NSArray *currentViews;
405-
__block NSUInteger currentVisibleViewsCount;
406-
407-
void (^cellAnimation)(id, NSUInteger, BOOL*) = ^(UIView *view, NSUInteger idx, BOOL *stop){
408-
BOOL fromMode = currentViews == fromViews;
409-
NSTimeInterval delay = ((float)idx / (float)currentVisibleViewsCount) * self.maxDelay;
410-
if (!fromMode) {
411-
[view setTransform:CGAffineTransformMakeTranslation(delta, 0)];
401+
NSArray *fromViews = [self visibleCellsForViewController:fromVC];
402+
NSArray *toViews = [self visibleCellsForViewController:toVC];
403+
404+
__block NSArray *currentViews;
405+
__block NSUInteger currentVisibleViewsCount;
406+
407+
void (^cellAnimation)(id, NSUInteger, BOOL*) = ^(UIView *view, NSUInteger idx, BOOL *stop){
408+
BOOL fromMode = currentViews == fromViews;
409+
NSTimeInterval delay = ((float)idx / (float)currentVisibleViewsCount) * self.maxDelay;
410+
if (!fromMode) {
411+
[view setTransform:CGAffineTransformMakeTranslation(delta, 0)];
412+
}
413+
void (^animation)() = ^{
414+
if (fromMode) {
415+
view.transform = CGAffineTransformMakeTranslation(-delta, 0);
416+
view.alpha = 0;
417+
} else {
418+
view.transform = CGAffineTransformIdentity;
419+
view.alpha = 1;
412420
}
413-
void (^animation)() = ^{
414-
if (fromMode) {
415-
view.transform = CGAffineTransformMakeTranslation(-delta, 0);
416-
view.alpha = 0;
417-
} else {
418-
view.transform = CGAffineTransformIdentity;
419-
view.alpha = 1;
420-
}
421-
};
422-
void (^completion)(BOOL) = ^(BOOL finished2){
423-
if (fromMode) {
424-
[view setTransform:CGAffineTransformIdentity];
425-
}
426-
};
427-
if (self.transitionType == AMWaveTransitionTypeSubtle) {
428-
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
429-
} else if (self.transitionType == AMWaveTransitionTypeNervous) {
430-
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
431-
} else if (self.transitionType == AMWaveTransitionTypeBounce){
432-
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:animation completion:completion];
421+
};
422+
void (^completion)(BOOL) = ^(BOOL finished2){
423+
if (fromMode) {
424+
[view setTransform:CGAffineTransformIdentity];
433425
}
434426
};
435-
436-
437-
currentViews = fromViews;
438-
NSArray *viewsArrays = @[fromViews, toViews];
439-
440-
for (currentViews in viewsArrays) {
441-
// Animates all views
442-
currentVisibleViewsCount = currentViews.count;
443-
[currentViews enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:cellAnimation];
427+
if (self.transitionType == AMWaveTransitionTypeSubtle) {
428+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
429+
} else if (self.transitionType == AMWaveTransitionTypeNervous) {
430+
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
431+
} else if (self.transitionType == AMWaveTransitionTypeBounce){
432+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:animation completion:completion];
444433
}
445-
}];
434+
};
435+
436+
437+
currentViews = fromViews;
438+
NSArray *viewsArrays = @[fromViews, toViews];
439+
440+
for (currentViews in viewsArrays) {
441+
// Animates all views
442+
currentVisibleViewsCount = currentViews.count;
443+
[currentViews enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:cellAnimation];
444+
}
446445
}
447446

448447
- (NSArray *)visibleCellsForViewController:(UIViewController*)viewController {
449448
NSArray *visibleCells = nil;
450-
449+
451450
if ([viewController respondsToSelector:@selector(visibleCells)]) {
452451
visibleCells = ((UIViewController<AMWaveTransitioning>*)viewController).visibleCells;
453452
} else if ([viewController respondsToSelector:@selector(tableView)]) {

0 commit comments

Comments
 (0)