加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift 3.0 遇到的一些问题

发布时间:2020-12-14 06:29:16 所属栏目:百科 来源:网络整理
导读:1、导航控制器跳转时隐藏tabbar 在导航控制器中重写以下方法 override func pushViewController(_ viewController: UIViewController ,animated: Bool) { if self .childViewControllers .count 0 { viewController .hidesBottomBarWhenPushed = true } supe

1、导航控制器跳转时隐藏tabbar

在导航控制器中重写以下方法

override func pushViewController(_ viewController: UIViewController,animated: Bool) {
        if self.childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController,animated: animated)
    }

2、设置控件y值从导航栏下面开始计算
在控制器中重写以下方法

override func loadView(){
        super.loadView()
        //设置y从导航栏下开始
        self.edgesForExtendedLayout = .bottom
    }

3、通过控制器名添加子控制器

private func addChildViewController(childControllerName : String,title : String,normalImage : String) {

        // 1.获取命名空间
        guard let clsName = Bundle.main.infoDictionary!["CFBundleExecutable"] else {
            print("命名空间不存在")
            return
        }
        // 2.通过命名空间和类名转换成类
        let cls : AnyClass? = NSClassFromString((clsName as! String) + "." + childControllerName)
        // swift 中通过Class创建一个对象,必须告诉系统Class的类型
        guard let clsType = cls as? BaseViewController.Type else {
            print("无法转换成BaseViewController")
            return
        }

        // 3.通过Class创建对象
        let childController = clsType.init()

        // 设置TabBar和Nav的标题
        childController.title = title
        childController.tabBarItem.image = UIImage(named: normalImage)
        // 包装导航控制器
        let nav = BaseNavViewController(rootViewController: childController)
        self.addChildViewController(nav)
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读