swift中UIViewController的使用

swift中UIViewController的使用,第1张

概述UIViewController视图控制器在iOS研发中不可或缺,基本上每一个页都的研发都会使用到。 在使用过程中,主要使用了以下几个方面。 1、视图控制器的属性设置。如背景颜色,适配,视图控制器数组属性等 2、视图控制器的生命周期的控制 3、视图控制器间的转场present,或push,以及相对应的dismiss,或pop …… // MARK: - 适配func autoSize(){

UIVIEwController视图控制器在iOS研发中不可或缺,基本上每一个页都的研发都会使用到。

在使用过程中,主要使用了以下几个方面。

1、视图控制器的属性设置。如背景颜色,适配,视图控制器数组属性等

2、视图控制器的生命周期的控制

3、视图控制器间的转场present,或push,以及相对应的dismiss,或pop

……

// MARK: - 适配func autoSize(){        if self.respondsToSelector(Selector("edgesForExtendedLayout"))        {            self.edgesForExtendedLayout = UIRectEdge.None        }                if self.respondsToSelector(Selector("extendedLayoutIncludesOpaquebars"))        {            self.extendedLayoutIncludesOpaquebars = false        }                if self.respondsToSelector(Selector("automaticallyAdjustsScrollVIEwInsets"))        {            self.automaticallyAdjustsScrollVIEwInsets = false        }}
// MARK: - 根视图控制器var isRootVIEwController:Bool{        get        {            if self.navigationController!.vIEwControllers.first!.isEqual(self)            {                return true            }                        return false        }}
 // MARK: - 视图控制器索引下标值var indexVIEwController:Int{        get        {            let indexVC = self.navigationController!.vIEwControllers.indexOf(self)!            return indexVC        }}
// MARK: - 返回上层视图控制器func backPrevIoUsController(){        if self.isRootVIEwController        {            self.dismissVIEwControllerAnimated(true,completion: nil)        }        else        {            if (self.presentedVIEwController != nil)            {                self.dismissVIEwControllerAnimated(true,completion: nil)            }            else            {                self.navigationController!.popVIEwControllerAnimated(true)            }        }}
overrIDe func loadVIEw() {                super.loadVIEw()                // 视图控制器背景颜色        self.vIEw.backgroundcolor = UIcolor.whitecolor()}
// present视图控制器let nextVC = PresentVIEwController()let nextNav = UINavigationController(rootVIEwController: nextVC)/*视图控制器翻转效果由下向上推出(默认模式) CoverVertical水平翻转 FlipHorizontal淡入淡出 Crossdissolve翻页效果 PartialCurl        注意:如果有导航视图控制器时,翻转效果设置在导航视图控制器;没有时则设置在视图控制器。*/nextNav.modalTransitionStyle = UIModalTransitionStyle.PartialCurl        self.presentVIEwController(nextNav,animated: true,completion: nil)
// 返回上一个视图控制器self.dismissVIEwControllerAnimated(true,completion: nil)
// push视图控制器let nextVC = PopVIEwController()// self.navigationController!.pushVIEwController(nextVC,animated: true)        // 转场动画1UIVIEw.beginAnimations(nil,context: nil)UIVIEw.setAnimationCurve(UIVIEwAnimationCurve.EaseInOut)UIVIEw.setAnimationDuration(0.6)self.navigationController!.pushVIEwController(nextVC,animated: true)UIVIEw.setAnimationTransition(uiviewanimationtransition.CurlUp,forVIEw: self.navigationController!.vIEw,cache: false)UIVIEw.commitAnimations()
// 转场动画2let animation = CATransition()animation.duration = 0.6animation.type = kCATransitionRevealanimation.timingFunction = camediatimingFunction(name: kcamediatimingFunctionEaseInEaSEOut)animation.subtype = kCATransitionFromBottomself.navigationController!.pushVIEwController(nextVC,animated: true)self.navigationController!.vIEw.layer.addAnimation(animation,forKey: nil)
// 返回上一个视图控制器self.navigationController!.popVIEwControllerAnimated(true)// 返回根视图控制器self.navigationController!.popToRootVIEwControllerAnimated(true)// 返回指定视图控制器let indexVC = self.navigationController!.vIEwControllers[2]self.navigationController!.popToVIEwController(indexVC,animated: true)

总结

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

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

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

原文地址:https://54852.com/web/1070907.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存