Commit b4774602 authored by 汪洋's avatar 汪洋

优化 present 动画

parent 8a33bb80
...@@ -9,15 +9,13 @@ ...@@ -9,15 +9,13 @@
#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,7 +28,6 @@ ...@@ -30,7 +28,6 @@
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];
...@@ -47,32 +44,25 @@ ...@@ -47,32 +44,25 @@
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;
...@@ -84,19 +74,17 @@ ...@@ -84,19 +74,17 @@
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;
...@@ -114,10 +102,7 @@ ...@@ -114,10 +102,7 @@
toVC.snapshot = nil; toVC.snapshot = nil;
} }
[transitionContext completeTransition:![transitionContext transitionWasCancelled]]; [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