星空网 > 软件开发 > 操作系统

自定义转场动画的实现

现在的APP有很多酷炫的动画,看了心痒痒地想加点动画到自己的APP上,增加一些交互效果.现在很常见的动画就是转场动画,先来介绍一下专场动画的实现.

1. 转场动画

其实iOS对转场动画的支持非常好,基本上只要实现几个协议就行了,把四个协议弄清楚了,基本上就可以在上面实现各种各样酷炫的转场动画了.

@protocol UIViewControllerContextTransitioning

故名思议,这个就是提供上下文.这个系统已经实现好了,可以直接得到fromViewController,toViewController,ContainerView等,直接看看源码就会用了.

@protocol UIViewControllerAnimatedTransitioning

这个是动画的核心,主要是实现

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext

就是在这个方法里来写动画效果 

@protocol UIViewControllerTransitioningDelegate

@protocol UINavigationControllerDelegate

这两个协议的作用是一样的,用大白话来说就是问你要不要用转场动画,主要的方法就是返回一个实现了UIViewControllerAnimatedTransitioning协议的动画

 

-(id< UIViewControllerAnimatedTransitioning >)animationControllerForPresentedController:(UIViewController )presented presentingController:(UIViewController )presenting sourceController:(UIViewController *)source;
对应self presentViewController

 -(id< UIViewControllerAnimatedTransitioning >)animationControllerForDismissedController:(UIViewController *)dismissed;

对应self dismissViewController

-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC

对应self.navigationController pushViewController

 主要就是上面三个方法.

还有一个协议@protocol UIViewControllerInteractiveTransitioning

这个主要是和手势有关,就是交互效果,我这实现的demo没有用这个.

 

2. demo效果

自定义转场动画的实现images/loading.gif' data-original="http://images2015.cnblogs.com/blog/775858/201511/775858-20151120195402561-1356707349.gif" />

 

3. demo

代码量很少,自己看看就可以实现自己的酷炫动画了.

github地址:https://github.com/stevenxiaoyang/NavTransition.git

欢迎大家一起交流进步

 

 

 


 




原标题:自定义转场动画的实现

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

谁说做东南亚Shopee不赚钱?只要抓住刚需想不赚钱都难:https://www.goluckyvip.com/news/3437.html
分享几个Shopee店铺选品的小技巧!:https://www.goluckyvip.com/news/3438.html
炙手可热的东南亚LAZADA平台,真的是“早期淘宝”吗?:https://www.goluckyvip.com/news/3439.html
全球最大航运公司马士基发出警告:中美贸易战将打击集装箱运输行业!:https://www.goluckyvip.com/news/344.html
Shopee店铺上新需要上新什么?市场是怎么样的?:https://www.goluckyvip.com/news/3440.html
震惊!欧洲FBA海派清关看似简单,却暗藏巨坑!!!:https://www.goluckyvip.com/news/3441.html
37号文今后是否会更新?一文详解关键信息 :https://www.kjdsnews.com/a/1836441.html
探讨内地人开设香港账户的可行性 :https://www.kjdsnews.com/a/1836442.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流