Swift基础之UITabBarController(这是在之前UITableView中直接添加的)

时间:2022-11-10 19:58:32

这些基础内容基本已经可以搭建项目框架,剩下的就是一些优化,细节和数据请求问题,慢慢更新....

在AppDelegate中创建方法

//创建方法执行UITabBarController

func createTabBar()

    {

        let tabBarContro = UITabBarController();

        

        let viewC = ViewController();

        viewC.tabBarItem.image = UIImage(named: "item1.png");

        let oneNavigation = UINavigationController.init(rootViewController: viewC);

        

        let firstVC = FirstViewController();

        firstVC.tabBarItem.image = UIImage(named: "item2.png");

        let twoNavigation = UINavigationController.init(rootViewController: firstVC);

        

        let secondVC = SecondViewController();

        secondVC.tabBarItem.image = UIImage(named: "item3.png");

        let threeNavigation = UINavigationController.init(rootViewController: secondVC);

        

        let navArray = [oneNavigation,twoNavigation,threeNavigation];

        tabBarContro.viewControllers = navArray;

        

        window?.rootViewController = tabBarContro;

}

点击第一个模块进入第二层界面后需要隐藏tabBar

//进入第二层界面隐藏UITabBarController

override func viewWillAppear(animated: Bool) {

        navigationController?.tabBarController?.tabBar.hidden = true;

    }

    override func viewWillDisappear(animated: Bool) {

        navigationController?.tabBarController?.tabBar.hidden = false;

    }