国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 怀集县| 开封市| 鲁山县| 阳朔县| 舟山市| 启东市| 巴南区| 瑞安市| 福清市| 年辖:市辖区| 北流市| 平和县| 德令哈市| 南靖县| 海丰县| 重庆市| 康乐县| 两当县| 手机| 沙洋县| 保山市| 滕州市| 固原市| 西峡县| 云浮市| 石屏县| 和政县| 凯里市| 吴川市| 城固县| 西乌珠穆沁旗| 宣化县| 虹口区| 昭通市| 江口县| 和政县| 新安县| 晋城| 大洼县| 灵丘县| 东宁县|