之前介绍一篇文章 自定义转场动画(一),主要介绍了Present的转场动画。今天介绍一下有关Push的转场动画。
准备:首先要两个UIViewController和一个继承与UIPercentDrivenInteractiveTransition的类。
ViewController1
ViewController2
PushTransitionAnimator
PushTransitionAnimator
.h
@interface PushTransitionAnimator : UIPercentDrivenInteractiveTransition<UIViewControllerAnimatedTransitioning,UIViewControllerTransitioningDelegate,UIGestureRecognizerDelegate>
@property (nonatomic, assign) BOOL isPop;//是push还是pop
.m
完成UIViewControllerAnimatedTransitioning协议
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
return self.transitionDuration;
}
//这里实现从下往上的Push
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext