iOS 转场动画的简介

有关转场动画的文章,多如牛毛,也有很多大神的文章,或是开源demo,我从中精简了主要流程,以及自己的开发经验,写了这篇文章,希望有所帮助。
早期的时候有一个Demo,在github上:
本想做一些转场动画的library,但是由于种种原因搁浅了。
本文也将结合这个Demo来做一些补充。

https://github.com/quinn0809/PresentTranslationDemo

一、CATranlation的转场动画

引用:iOS 动画 —— CATransition : https://www.jianshu.com/p/239cf81eb1eb
这个适合uiview的转场,或者简单的viewcontroller的转场,估计很难满足你的需求。

二、UIViewControllerTransitioningDelegateUINavigationControllerDelegate

这样讲:一个复杂的、自定义的、完整的转场动画,包括入场手势交互+入场动画+出场手势交互+出场动画

然而,大部分转场动画为:入场动画+出场动画
入场手势交互+入场动画+出场动画
入场动画
出场手势交互+出场动画
入场动画+出场手势交互+出场动画

UIViewControllerAnimatedTransitioning 定义了转场动画的细节:包括时间和具体的转场动画
UIPercentDrivenInteractiveTransition 定义了转场动画的手势进度,是否取消,是否完成等
UIViewControllerTransitioningDelegate 只是定义了我该如何选择转场动画,如何选择手势交互

也就是说:UIViewControllerTransitioningDelegate 是管理UIPercentDrivenInteractiveTransition 和 UIViewControllerAnimatedTransitioning 的

联系如下:

UIViewControllerTransitioningDelegate
	func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
   
        return X<UIViewControllerAnimatedTransitioning>
    }
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
   
        return Y<UIViewControllerAnimatedTransitioning>
    }

    func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
   
        return Z<UIViewControllerInteractiveTransitioning>
    }
    func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
   
        //ToDo:present interaction
        return W<UIViewControllerInteractiveTransitioning>
    }

    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
   
        //ToDo:.....
        return nil
    }

到目前为止:你已经了解了30%了。
注意:UIViewControllerTransitioningDelegate --》present、dismiss

这个适用于模态转场。
那么导航转场动画呢?

UINavigationControllerDelegate ----》 push、pop

 //动画操作
    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?{
   
    	if
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值