Created
May 15, 2014 12:46
-
-
Save pietrorea/08f1a9c861561bcd36fd to your computer and use it in GitHub Desktop.
TPSpringyModalTransition - modal transition that bounces off the top like a spring
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
// TPSpringyModalTransition.h | |
// iPeru | |
// | |
// Created by Pietro Rea on 5/4/14. | |
// Copyright (c) 2014 Pietro Rea. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface TPSpringyModalTransition : NSObject <UIViewControllerAnimatedTransitioning> | |
@property (assign, nonatomic) BOOL presenting; | |
@end |
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
// | |
// TPSpringyModalTransition.m | |
// iPeru | |
// | |
// Created by Pietro Rea on 5/4/14. | |
// Copyright (c) 2014 Pietro Rea. All rights reserved. | |
// | |
#import "TPSpringyModalTransition.h" | |
#import <FrameAccessor/FrameAccessor.h> | |
#define kHeightDelta 30 | |
@implementation TPSpringyModalTransition | |
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext | |
{ | |
return 0.45; | |
} | |
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext | |
{ | |
UIViewController *presentingVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; | |
UIViewController *presentedVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; | |
if (self.presenting) { | |
[transitionContext.containerView addSubview:presentingVC.view]; | |
[transitionContext.containerView addSubview:presentedVC.view]; | |
presentedVC.view.height += kHeightDelta; | |
presentedVC.view.top += presentedVC.view.height; | |
[UIView animateWithDuration:[self transitionDuration:transitionContext] | |
delay:0.0 | |
usingSpringWithDamping:0.70 | |
initialSpringVelocity:0.9 | |
options:0 | |
animations:^{ | |
presentedVC.view.top = presentingVC.view.top; | |
} completion:^(BOOL finished) { | |
[transitionContext completeTransition:YES]; | |
presentedVC.view.height -= kHeightDelta; | |
}]; | |
} else { | |
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ | |
presentingVC.view.frame = CGRectOffset(presentingVC.view.frame, 0, presentingVC.view.frame.size.height); | |
} completion:^(BOOL finished) { | |
[transitionContext.containerView addSubview:presentingVC.view]; | |
[transitionContext.containerView addSubview:presentedVC.view]; | |
[transitionContext completeTransition:YES]; | |
}]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment