Skip to content

Commit

Permalink
Merge pull request #1 from maxmamis/feature/slide-up-animation
Browse files Browse the repository at this point in the history
Thanks for your contribution!
  • Loading branch information
angelolloqui committed May 5, 2014
2 parents f721048 + d4c95fb commit 7da5053
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 43 deletions.
9 changes: 9 additions & 0 deletions src/AGBlurTransitionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#import <Foundation/Foundation.h>

typedef NS_ENUM (NSInteger, AGBlurTransitionAnimationType)
{
AGBlurTransitionAnimationTypeDefault = 0,
AGBlurTransitionAnimationTypeSlide
};

@interface AGBlurTransitionDelegate : NSObject <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning>

/** Configures the animation duration. Defaults to 0.5 */
Expand All @@ -25,4 +31,7 @@
/** Configures tint color of blur image. Defaults to black 0.3 alpha */
@property (nonatomic, strong) UIColor *tintColor;

/** Configures the style of animation. Defaults to AGBlurTransitionAnimationTypeDefault. */
@property (nonatomic, assign) AGBlurTransitionAnimationType animationType;

@end
101 changes: 58 additions & 43 deletions src/AGBlurTransitionDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,34 @@ - (void)animateOpenTransition:(id <UIViewControllerContextTransitioning>)transit
toViewController.view.frame = UIEdgeInsetsInsetRect(finalFrame, self.insets);
[containerView addSubview:self.backgroundView];
containerView.frame = finalFrame;

// Set initial state of animation
toViewController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1);
if (self.animationType == AGBlurTransitionAnimationTypeSlide) {
toViewController.view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0.f, toViewController.view.frame.size.height);
}
else {
toViewController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1);
}
self.bluredImageView.alpha = 0.0;

// Animate
[UIView animateWithDuration:duration
delay:0.0
usingSpringWithDamping:0.6
initialSpringVelocity:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
toViewController.view.transform = CGAffineTransformIdentity;
blurImageView.alpha = 1.0;
} completion:^(BOOL finished) {
// Inform the context of completion
[transitionContext completeTransition:YES];
//Hack! the view controller is resized and background view moved out of the transition view. We need to replace it
UIView *parent = toViewController.view.superview;
[self.backgroundView addSubview:toViewController.view];
[parent addSubview:self.backgroundView];
}];
animations: ^{
toViewController.view.transform = CGAffineTransformIdentity;
blurImageView.alpha = 1.0;
} completion: ^(BOOL finished) {
// Inform the context of completion
[transitionContext completeTransition:YES];

//Hack! the view controller is resized and background view moved out of the transition view. We need to replace it
UIView *parent = toViewController.view.superview;
[self.backgroundView addSubview:toViewController.view];
[parent addSubview:self.backgroundView];
}];
}

- (void)animateCloseTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
Expand All @@ -130,43 +135,53 @@ - (void)animateCloseTransition:(id <UIViewControllerContextTransitioning>)transi
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
NSTimeInterval duration = [self transitionDuration:transitionContext];
UIView *containerView = [transitionContext containerView];

// Add the view and backgrounds
[containerView addSubview:toViewController.view];
[containerView addSubview:self.bluredImageView];
[containerView addSubview:fromViewController.view];

// Animate with keyframes
[UIView animateKeyframesWithDuration:duration
delay:0.0
options:UIViewKeyframeAnimationOptionCalculationModeCubic
animations:^{
// keyframe one
[UIView addKeyframeWithRelativeStartTime:0.0
relativeDuration:0.2
animations:^{
fromViewController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.2, 1.2);
}];
// keyframe two
[UIView addKeyframeWithRelativeStartTime:0.2
relativeDuration:0.6
animations:^{
fromViewController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.00001, 0.00001);
self.bluredImageView.alpha = 0.0;
}];
[UIView addKeyframeWithRelativeStartTime:0.0
relativeDuration:1.0
animations:^{
self.bluredImageView.alpha = 0.0;
}];
}
completion:^(BOOL finished) {
[self.bluredImageView removeFromSuperview];
self.backgroundView = nil;
[transitionContext completeTransition:YES];
}];
}
animations: ^{
// keyframe one
[UIView addKeyframeWithRelativeStartTime:0.0
relativeDuration:0.2
animations: ^{
if (self.animationType == AGBlurTransitionAnimationTypeSlide) {
fromViewController.view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, -fromViewController.view.frame.size.height * .2);
}
else {
fromViewController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.2, 1.2);
}
}];
// keyframe two
[UIView addKeyframeWithRelativeStartTime:0.2
relativeDuration:0.6
animations: ^{
if (self.animationType == AGBlurTransitionAnimationTypeSlide) {
fromViewController.view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, fromViewController.view.frame.size.height);
}
else {
fromViewController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.00001, 0.00001);
}
self.bluredImageView.alpha = 0.0;
}];
[UIView addKeyframeWithRelativeStartTime:0.0
relativeDuration:1.0
animations: ^{
self.bluredImageView.alpha = 0.0;
}];
}

completion: ^(BOOL finished) {
[self.bluredImageView removeFromSuperview];
self.backgroundView = nil;
[transitionContext completeTransition:YES];
}];
}

- (UIImage *)createImageFromView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
Expand Down

0 comments on commit 7da5053

Please sign in to comment.