从导航堆栈弹出UIViewController时UITabBarItem向上移动

时间:2018-12-10 07:07:04

标签: ios swift uitabbarcontroller uitabbar uitabbaritem

我创建了UITabBarController类来以编程方式创建标签栏。我有两个选项卡,分别用于两个视图控制器,分别是FirstViewController和SecondViewController。从第一个视图控制器,我想推送另一个名为DetailViewController的视图控制器。在DetailViewController中,我想在推送时隐藏标签栏,因此我选中了属性检查器上的“在推送时隐藏底部栏”按钮。 推送时它可以按预期工作,但是当我弹出视图控制器时,选项卡栏设计变得混乱。

问题:

故事板:

DetailViewController的属性检查器:

Screen shot

TabViewController类:

class TabBarViewController: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()
    createTab()
 }

func createTab() {
    let firstVC = self.storyboard?.instantiateViewController(withIdentifier: "FirstNav") as! UINavigationController

    let popularIcon = UITabBarItem(title: "", image: UIImage(named: "Setting"), selectedImage: UIImage(named: "Setting"))
    popularIcon.imageInsets = UIEdgeInsets.init(top: 6, left: 0, bottom: -6, right: 0)
    firstVC.tabBarItem = popularIcon

    let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "SecondNav") as! UINavigationController
    let searchIcon = UITabBarItem(title: "",image: UIImage(named: "unselected_Search_Icn"),selectedImage: UIImage(named: "Search_Icn"))
    searchIcon.imageInsets = UIEdgeInsets.init(top: 6, left: 0, bottom: -6, right: 0)
    secondVC.tabBarItem = searchIcon

    self.viewControllers = [firstVC, secondVC]
    self.tabBar.barTintColor = UIColor.red
    }
 }

FirstViewController类:

class FirstViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
}


@IBAction func buttonTapped() {
    let detailVC = self.storyboard?.instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
    self.navigationController?.pushViewController(detailVC, animated: true)
     }
   }

DetailViewController类

class DetailViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
}


@IBAction func popTapped() {
    self.navigationController?.popViewController(animated: true)
    }  
 }

0 个答案:

没有答案