国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS swift實(shí)現(xiàn)轉(zhuǎn)場動畫的方法示例

2020-07-26 02:45:23
字體:
供稿:網(wǎng)友

轉(zhuǎn)場動畫介紹

轉(zhuǎn)場動畫在我們?nèi)粘i_發(fā)中是經(jīng)常遇到的,所謂轉(zhuǎn)場動畫,就是一個(gè)控制器的view切到另一個(gè)控制器的view上過程中過的動畫效果。本例子是實(shí)現(xiàn)了在導(dǎo)航控制器的titleView邊上慢慢彈出一個(gè)控制器。下面話不多說,來一起看看詳細(xì)的介紹:

效果圖:


專場前


專場后

示例代碼

首先自定義一個(gè)animator類。在需要轉(zhuǎn)場的控制器內(nèi),設(shè)置代理

 //需要設(shè)置轉(zhuǎn)場動畫的控制器titleViewVc.transitioningDelegate = aniamator//這里的animator是animator的實(shí)例

下面是animator類中的代碼

class animatorTool: NSObject { lazy var isPresent = false var callBack : ((isPresented:Bool)->())?//向外界傳遞動畫是否正在顯示 init(callBack : ((isPresented:Bool)->())) {  self.callBack = callBack }//自定義構(gòu)造方法,便于給閉包賦值}extension animatorTool:UIViewControllerTransitioningDelegate{ func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {  return AWYPresentationController(presentedViewController: presented, presentingViewController: presenting)//AWYPresentationController是自定義繼承自UIPresentationController的類,是為了設(shè)置modal出來的vc的view的大小 } func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {  isPresent = true  self.callBack!(isPresented: isPresent)  return self } func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {  isPresent = false  self.callBack!(isPresented: isPresent)  return self }}extension animatorTool:UIViewControllerAnimatedTransitioning{ func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {  return 0.5//動畫時(shí)長 } func animateTransition(transitionContext: UIViewControllerContextTransitioning) {  isPresent ?animatetransitionForPresented(transitionContext) : animatetransitionForDismissed(transitionContext) } func animatetransitionForPresented(transitonContext:UIViewControllerContextTransitioning){  let aimView = transitonContext.viewForKey(UITransitionContextToViewKey)!  transitonContext.containerView()?.addSubview(aimView)  aimView.transform = CGAffineTransformMakeScale(1.0, 0.0)  UIView.animateWithDuration(transitionDuration(transitonContext), animations: {   aimView.layer.anchorPoint = CGPointMake(0.5, 0.0)   aimView.transform = CGAffineTransformIdentity  }) { (_) in   transitonContext.completeTransition(true)  } } func animatetransitionForDismissed(transitonContext:UIViewControllerContextTransitioning){  let aimView = transitonContext.viewForKey(UITransitionContextFromViewKey)!  transitonContext.containerView()?.addSubview(aimView)  UIView.animateWithDuration(transitionDuration(transitonContext), animations: {   aimView.layer.anchorPoint = CGPointMake(0.5, 0.0)   aimView.transform = CGAffineTransformMakeScale(1.0, 0.001)//留一點(diǎn)值,這樣會有動畫效果  }) { (_) in   transitonContext.completeTransition(true)  } }}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對武林網(wǎng)的支持。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桦川县| 如皋市| 武汉市| 伽师县| 霍城县| 大姚县| 南丰县| 灯塔市| 丘北县| 乌鲁木齐市| 马关县| 灵山县| 弋阳县| 上虞市| 沽源县| 迭部县| 开阳县| 获嘉县| 浑源县| 金阳县| 当阳市| 乌拉特前旗| 安庆市| 琼结县| 新疆| 斗六市| 宝山区| 剑河县| 崇礼县| 西乌| 河源市| 商河县| 明溪县| 沁源县| 沙洋县| 民勤县| 海原县| 武邑县| 同仁县| 宜川县| 东乌珠穆沁旗|