Commit b4774602 authored by 汪洋's avatar 汪洋

优化 present 动画

parent 8a33bb80
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
animation.transitionType = operation; animation.transitionType = operation;
return animation; return animation;
} }
return nil; return nil;
} }
......
...@@ -9,16 +9,14 @@ ...@@ -9,16 +9,14 @@
#import "GMPresentAnimation.h" #import "GMPresentAnimation.h"
#import "UIViewController+PushType.h" #import "UIViewController+PushType.h"
@interface GMPresentAnimation() <UIViewControllerAnimatedTransitioning> @interface GMPresentAnimation() <UIViewControllerAnimatedTransitioning>
@property(nonatomic,assign)NSTimeInterval duration; @property(nonatomic, assign) NSTimeInterval duration;
@end @end
@implementation GMPresentAnimation @implementation GMPresentAnimation
- (instancetype)init - (instancetype)init {
{ // 默认 push 动画时间0.6
// 默认 push 动画时间0.6
if (self = [super init]) { if (self = [super init]) {
// self.duration = 0.6; self.duration = 0.6;
self.duration = 0.6;
} }
return self; return self;
} }
...@@ -30,12 +28,11 @@ ...@@ -30,12 +28,11 @@
NSTimeInterval duration = [self transitionDuration:transitionContext]; NSTimeInterval duration = [self transitionDuration:transitionContext];
CGRect bound = [[UIScreen mainScreen] bounds]; CGRect bound = [[UIScreen mainScreen] bounds];
fromVC.view.hidden = YES; fromVC.view.hidden = YES;
[[transitionContext containerView] addSubview:fromVC.snapshot]; [[transitionContext containerView] addSubview:fromVC.snapshot];
[[transitionContext containerView] addSubview:toVC.view]; [[transitionContext containerView] addSubview:toVC.view];
[[toVC.navigationController.view superview] insertSubview:fromVC.snapshot belowSubview:toVC.navigationController.view]; [[toVC.navigationController.view superview] insertSubview:fromVC.snapshot belowSubview:toVC.navigationController.view];
toVC.navigationController.view.layer.anchorPoint = CGPointMake(0.5, 2.0); toVC.navigationController.view.layer.anchorPoint = CGPointMake(0.5, 2.0);
...@@ -47,77 +44,65 @@ ...@@ -47,77 +44,65 @@
delay:0 delay:0
usingSpringWithDamping:1.0 usingSpringWithDamping:1.0
initialSpringVelocity:0 initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear options:UIViewAnimationOptionCurveEaseInOut
animations:^{ animations:^{
fromVC.snapshot.transform = CGAffineTransformMakeTranslation(0, 0); fromVC.snapshot.transform = CGAffineTransformMakeTranslation(0, 0);
toVC.navigationController.view.transform = CGAffineTransformMakeTranslation(0, 0); toVC.navigationController.view.transform = CGAffineTransformMakeTranslation(0, 0);
} }
completion:^(BOOL finished) { completion:^(BOOL finished) {
fromVC.view.hidden = NO; fromVC.view.hidden = NO;
[fromVC.snapshot removeFromSuperview]; [transitionContext completeTransition:YES];
[transitionContext completeTransition:YES];
}]; }];
} }
- (void)pop:(id<UIViewControllerContextTransitioning>)transitionContext - (void)pop:(id<UIViewControllerContextTransitioning>)transitionContext {
{
UIViewController * fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController * fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController * toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; UIViewController * toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSTimeInterval duration = [self transitionDuration:transitionContext]; NSTimeInterval duration = [self transitionDuration:transitionContext];
CGRect bound = [[UIScreen mainScreen] bounds]; CGRect bound = [[UIScreen mainScreen] bounds];
[fromVC.view addSubview:fromVC.snapshot]; [fromVC.view addSubview:fromVC.snapshot];
fromVC.navigationController.navigationBar.hidden = YES; fromVC.navigationController.navigationBar.hidden = YES;
// 添加阴影 // 添加阴影
fromVC.snapshot.layer.shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.8].CGColor; fromVC.snapshot.layer.shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.8].CGColor;
fromVC.snapshot.layer.shadowOffset = CGSizeMake(-3, 0); fromVC.snapshot.layer.shadowOffset = CGSizeMake(-3, 0);
fromVC.snapshot.layer.shadowOpacity = 0.5; fromVC.snapshot.layer.shadowOpacity = 0.5;
fromVC.view.layer.anchorPoint = CGPointMake(0.5, 2.5); fromVC.view.layer.anchorPoint = CGPointMake(0.5, 2.5);
fromVC.view.frame = bound; fromVC.view.frame = bound;
toVC.view.hidden = YES;
toVC.view.hidden = YES;
[[transitionContext containerView] addSubview:toVC.view]; [[transitionContext containerView] addSubview:toVC.view];
[[transitionContext containerView] addSubview:toVC.snapshot]; [[transitionContext containerView] addSubview:toVC.snapshot];
[[transitionContext containerView] sendSubviewToBack:toVC.snapshot]; [[transitionContext containerView] sendSubviewToBack:toVC.snapshot];
[UIView animateWithDuration:duration [UIView animateWithDuration:duration
delay:0 delay:0
usingSpringWithDamping:1.0 usingSpringWithDamping:1.0
initialSpringVelocity:0 initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear options:UIViewAnimationOptionCurveEaseInOut
animations:^{ animations:^{
fromVC.view.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(bound)); fromVC.view.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(bound));
toVC.snapshot.alpha = 1; toVC.snapshot.alpha = 1;
} }
completion:^(BOOL finished) { completion:^(BOOL finished) {
toVC.navigationController.navigationBar.hidden = NO; toVC.navigationController.navigationBar.hidden = NO;
toVC.view.hidden = NO; toVC.view.hidden = NO;
[fromVC.snapshot removeFromSuperview];
[toVC.snapshot removeFromSuperview];
if (![transitionContext transitionWasCancelled]) [fromVC.snapshot removeFromSuperview];
{ [toVC.snapshot removeFromSuperview];
toVC.snapshot = nil;
}
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
if (![transitionContext transitionWasCancelled])
{
toVC.snapshot = nil;
}
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}]; }];
} }
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext - (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment