Last active
January 7, 2016 22:08
-
-
Save averydev/8535f13c1d29252e72ee to your computer and use it in GitHub Desktop.
Objective-C Animator based on http://netsplit.com/custom-ios-segues-transitions-and-animations-the-right-way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation ELFFadeAndSlidePushAnimator | |
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{ | |
return 0.35; | |
} | |
-(void) animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{ | |
UIView * containerView = [transitionContext containerView]; | |
NSTimeInterval duration = [self transitionDuration:transitionContext]; | |
UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey]; | |
UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey]; | |
toView.alpha = 0.f; | |
CGRect toFinalFrame = fromView.frame; | |
CGRect toStartFrame = fromView.frame; | |
toStartFrame.origin.x += 200; | |
CGRect fromFinalFrame = fromView.frame; | |
fromFinalFrame.origin.x -= 80; | |
toView.frame = toStartFrame; | |
[containerView addSubview:toView]; | |
[UIView animateWithDuration:duration animations:^{ | |
toView.alpha = 1.f; | |
toView.frame = toFinalFrame; | |
fromView.frame = fromFinalFrame; | |
fromView.alpha = 0.f; | |
} completion:^(BOOL finished) { | |
BOOL cancelled = [transitionContext transitionWasCancelled]; | |
[transitionContext completeTransition:!cancelled]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment