@interfacePresentAnimator : NSObject<UIViewControllerAnimatedTransitioning>@end@implementationPresentAnimator#pragma mark - UIViewControllerContextTransitioning-(void)animateTransition:(nonnullid<UIViewControllerContextTransitioning>)transitionContext{// from -> toUIViewController*fromViewController=[transitionContextviewControllerForKey:UITransitionContextFromViewControllerKey];UIViewController*toViewController=[transitionContextviewControllerForKey:UITransitionContextToViewControllerKey];// contrainerUIView*containerView=transitionContext.containerView;// from -> toUIView*fromView=[transitionContextviewForKey:UITransitionContextFromViewKey];UIView*toView=[transitionContextviewForKey:UITransitionContextToViewKey];// add[containerViewaddSubview:toView];// animationtoView.alpha=0;toView.frame=CGRectMake(fromView.frame.origin.x,CGRectGetMaxY(fromView.frame)/2,fromView.frame.size.width,fromView.frame.size.height);[UIViewanimateWithDuration:[selftransitionDuration:transitionContext]animations:^{toView.alpha=1;toView.frame=[transitionContextfinalFrameForViewController:toViewController];}completion:^(BOOLfinished){[transitionContextcompleteTransition:![transitionContexttransitionWasCancelled]];}];}-(NSTimeInterval)transitionDuration:(nullableid<UIViewControllerContextTransitioning>)transitionContext{return0.25;}@end
创建DismissAnimator
123456789101112131415161718192021222324
@interfaceDismissAnimator : NSObject<UIViewControllerAnimatedTransitioning>@end@implementationDismissAnimator#pragma mark - UIViewControllerContextTransitioning-(void)animateTransition:(nonnullid<UIViewControllerContextTransitioning>)transitionContext{// from -> toUIView*fromView=[transitionContextviewForKey:UITransitionContextFromViewKey];// animationfromView.alpha=1;[UIViewanimateWithDuration:[selftransitionDuration:transitionContext]animations:^{fromView.alpha=0;}completion:^(BOOLfinished){[transitionContextcompleteTransition:![transitionContexttransitionWasCancelled]];}];}-(NSTimeInterval)transitionDuration:(nullableid<UIViewControllerContextTransitioning>)transitionContext{return0.25;}@end