Swift转场动画的使用

Swift转场动画的使用,第1张

概述ViewController.swift<主控制器> 创建一个按钮,点击按钮时d出新的控制器 //PopoverTableViewController:d出控制器的名字let viewController = PopoverTableViewController()//制定一个转场代理:popoverAnimatorviewController.transitioningDelegate = VIEwController.swift<主控制器> 创建一个按钮,点击按钮时d出新的控制器
//PopovertableVIEwController:d出控制器的名字let vIEwController = PopovertableVIEwController()//制定一个转场代理:popoverAnimatorvIEwController.TransitioningDelegate = popoverAnimator//设置转场样式:自定义vIEwController.modalPresentationStyle = UIModalPresentationStyle.Custom//动画d出菜单presentVIEwController(vIEwController,animated: true,completion: nil)//懒加载转场private lazy var popoverAnimator: PopoverAnimator = {    let popoverAnimator = PopoverAnimator()    //在这里设置d出菜单的位置和大小    popoverAnimator.presentFrame = CGRectMake(UIScreen.mainScreen().bounds.size.wIDth / 2 - 100,56,200,350)    return popoverAnimator}()
PopoverAnimator.Swift<转场代理>
//实现代理方法,告诉系统谁来负责转场动画func presentationControllerForPresentedVIEwController(presented: UIVIEwController,presentingVIEwController presenting: UIVIEwController,sourceVIEwController source: UIVIEwController) -> UIPresentationController? {    let pc = PopoverPresentAtionController(presentedVIEwController: presented,presentingVIEwController: presenting)    //设置菜单的大小    pc.presrntFrame = presentFrame    return pc}//只要实现了以下方法,系统默认的动画效果就没有了,需要自己实现func animationControllerForPresentedController(presented: UIVIEwController,presentingController presenting: UIVIEwController,sourceController source: UIVIEwController) -> UIVIEwControllerAnimatedTransitioning? {    //展现动画执行的 *** 作    return self}func animationControllerFordismissedController(dismissed: UIVIEwController) -> UIVIEwControllerAnimatedTransitioning? {    //消失动画执行的 *** 作    return self}func TransitionDuration(TransitionContext: UIVIEwControllerContextTransitioning?) -> NSTimeInterval {    //动画时长    return 0.25}
PopoverPresentAtionController.swift<管理d出> 继承于: UIPresentationController 所有的UIVIEwController的presentation都是由UIPresentationController管理的。在UIPresentationController中可以定义content和Chrome的动画,可以根据大小的变化来改变content大小,可以根据系统的不同,来改变展示方式,UIPresentationController也是可复用的,可以很容易的拿到其他的UIVIEwController中去使用。 d出的,可以和用户交互的Controller叫做PresentedVIEwController,而后面那个被部分遮挡的UIVIEwController叫做PresentingVIEwController,而在UIPresentationController中,PresentedVIEwController是presentation的content,而PresentingVIEwController叫做Chrome 摘自:http://www.15yan.com/story/jlkJnPmVGzc/
/** 重写初始化方法,用于创建负责转场的动画 - parameter presentedVIEwController: 被展现的控制器 - parameter presentingVIEwController: 发起的控制器 */overrIDe init(presentedVIEwController: UIVIEwController,presentingVIEwController: UIVIEwController) {    super.init(presentedVIEwController: presentedVIEwController,presentingVIEwController: presentingVIEwController)}/** 重写containerVIEwWillLayoutSubvIEws,在即将布局转场子视图时调用 */overrIDe func containerVIEwWillLayoutSubvIEws() {    //修改d出视图的大小    //presentedVIEw: 被展现的视图    //containerVIEw: 容器视图}/// 懒加载蒙版效果private lazy var converVIEw: UIVIEw = {    //创建蒙版    let vIEw = UIVIEw()    vIEw.backgroundcolor = UIcolor(white: 0.0,Alpha: 0.3)    vIEw.frame = UIScreen.mainScreen().bounds    //为蒙版vIEw添加一个监听,点击蒙版的时候,转场消失    let tap = UITapGestureRecognizer(target: self,action: #selector(PopoverPresentAtionController.close))    vIEw.addGestureRecognizer(tap)    return vIEw}()///关闭菜单func close() {    presentedVIEwController.dismissVIEwControllerAnimated(true,completion: nil)}
PopovertableVIEwController.swift是d出的菜单,自己在里面布局 demo下载:https://github.com/1170197998/transitioningAnimation 总结

以上是内存溢出为你收集整理的Swift转场动画的使用全部内容,希望文章能够帮你解决Swift转场动画的使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1076928.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存