Skip to content

Instantly share code, notes, and snippets.

@hasanadil
Created June 28, 2014 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasanadil/47e97ab56b5273b8a90e to your computer and use it in GitHub Desktop.
Save hasanadil/47e97ab56b5273b8a90e to your computer and use it in GitHub Desktop.
//
// ASTransitionAnimator.m
// Maps
//
// Created by Hasan on 6/16/14.
// Copyright (c) 2014 AssembleLabs. All rights reserved.
//
#import "ASSlideUpTransitionAnimator.h"
@implementation ASSlideUpTransitionAnimator
// This is used for percent driven interactive transitions, as well as for container controllers that have companion animations that might need to
// synchronize with the main animation.
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 0.3;
}
// This method can only be a nop if the transition is interactive and not a percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
// Grab the from and to view controllers from the context
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
CGRect bounds = fromViewController.view.bounds;
if (self.presenting) {
fromViewController.view.userInteractionEnabled = NO;
[transitionContext.containerView addSubview:fromViewController.view];
[transitionContext.containerView addSubview:toViewController.view];
toViewController.view.alpha = 0;
toViewController.view.frame = CGRectMake(0, bounds.size.height, bounds.size.width, bounds.size.height);
[UIView animateWithDuration:[self transitionDuration:transitionContext]
delay:0.3
usingSpringWithDamping:0.5
initialSpringVelocity:0.3
options:UIViewAnimationOptionAllowUserInteraction animations:^{
fromViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
toViewController.view.frame = CGRectMake(0, 0, bounds.size.width, bounds.size.height);
toViewController.view.alpha = 1.0f;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
else {
toViewController.view.userInteractionEnabled = YES;
[transitionContext.containerView addSubview:toViewController.view];
[transitionContext.containerView addSubview:fromViewController.view];
[UIView animateWithDuration:[self transitionDuration:transitionContext]
delay:0.3
usingSpringWithDamping:0.5
initialSpringVelocity:0.5
options:UIViewAnimationOptionAllowUserInteraction animations:^{
toViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
fromViewController.view.alpha = 0.0f;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment