Last active
January 3, 2016 17:37
-
-
Save Athosone/2beba2407ea4cf5131d2 to your computer and use it in GitHub Desktop.
Animation->Popup with a bump effect
This file contains hidden or 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
// | |
// CustomModalAnimation.m | |
// Wineot | |
// | |
// Created by Werck Ayrton on 18/02/2015. | |
// Copyright (c) 2015 wineot. All rights reserved. | |
// | |
#import "CustomModalAnimation.h" | |
#pragma mark ->PresentingAnimationController | |
@interface PresentingAnimationController () | |
@end | |
@implementation PresentingAnimationController | |
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext | |
{ | |
return 0.5f; | |
} | |
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext | |
{ | |
UIView *fromView = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view; | |
fromView.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed; | |
fromView.userInteractionEnabled = NO; | |
UIView *toView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view; | |
//TODO find a way to have custom value to replace 50 | |
toView.frame = CGRectMake(0, | |
0, | |
self.toViewWidth, | |
self.toViewHeight); | |
//CGRectGetWidth(transitionContext.containerView.bounds) - self.toViewWidth, | |
//CGRectGetHeight(transitionContext.containerView.bounds) - self.toViewHeight); | |
CGPoint p = CGPointMake(transitionContext.containerView.center.x, -transitionContext.containerView.center.y); | |
toView.center = p; | |
[transitionContext.containerView addSubview:toView]; | |
POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY]; | |
positionAnimation.toValue = @(transitionContext.containerView.center.y); | |
positionAnimation.springBounciness = 10; | |
[positionAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) { | |
[transitionContext completeTransition:YES]; | |
}]; | |
POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; | |
scaleAnimation.springBounciness = 20; | |
scaleAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(1.2, 1.4)]; | |
[toView.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"]; | |
[toView.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnimation"]; | |
} | |
@end | |
#pragma mark ->DismissingAnimationController | |
@implementation DismissingAnimationController | |
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext | |
{ | |
return 0.5f; | |
} | |
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext | |
{ | |
UIView *toView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view; | |
toView.tintAdjustmentMode = UIViewTintAdjustmentModeNormal; | |
toView.userInteractionEnabled = YES; | |
UIView *fromView = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view; | |
POPBasicAnimation *closeAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerPositionY]; | |
closeAnimation.toValue = @(-fromView.layer.position.y); | |
[closeAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) { | |
[transitionContext completeTransition:YES]; | |
}]; | |
POPSpringAnimation *scaleDownAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; | |
scaleDownAnimation.springBounciness = 20; | |
scaleDownAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)]; | |
[fromView.layer pop_addAnimation:closeAnimation forKey:@"closeAnimation"]; | |
[fromView.layer pop_addAnimation:scaleDownAnimation forKey:@"scaleDown"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment