使用“ hidesBottomBarWhenPushed = true”隐藏选项卡栏后,屏幕底部黑色闪烁

时间:2020-06-17 15:06:38

标签: ios swift iphone ios-autolayout ios-animations

当尝试通过覆盖ViewController的init方法并在其中添加hidesBottomBarWhenPushed = true来隐藏我的标签栏时,我偶然发现了奇怪的动画(?)故障。

我还试图在ViewController的viewDidLoad和viewWillAppear中使用以下代码隐藏选项卡栏。结果是相同的-在以前的选项卡栏位置出现黑色闪烁。

self.navigationController?.tabBarController?.tabBar.isHidden = true
self.extendedLayoutIncludesOpaqueBars = true

似乎是什么问题?预先感谢!

这是我的ViewController的代码,必须在其中隐藏标签栏。

class CreateTaskViewController: UIViewController {

weak var coordinator: Coordinator?
private let createTaskView = CreateTaskView()

override func loadView() {
    createTaskView.viewController = self
    self.view = createTaskView
}

override func viewDidLoad() {
    super.viewDidLoad()

}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    self.hidesBottomBarWhenPushed = true
}

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
}

也是我的UITabBarController的子类代码

class TabBarController: UITabBarController {

    private let homeCoordinator = HomeCoordinator(navigationController: UINavigationController())
    private let createTaskCoordinator = CreateTaskCoordinator(navigationController: UINavigationController())
    private let categoriesCoordinator = CategoriesCoordinator(navigationController: UINavigationController())
    private let calendarCoordinator = CalendarCoordinator(navigationController: UINavigationController())

    weak var coordinator: TabBarCoordinator?

    override func viewWillLayoutSubviews() {
        tabBar.backgroundImage = UIImage.gradientImageWithBounds(bounds: tabBar.bounds, colors: [Colors.tabBarTopGradient, Colors.tabBarBottomGradient])
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        delegate = self
        homeCoordinator.start()
        createTaskCoordinator.start()
        categoriesCoordinator.start()
        calendarCoordinator.start()

        let imageForHomeView = UIImage(systemName: "house")
        let imageForCreateTaskView = UIImage(systemName: "plus.circle")
        let imageForCategoriesVIew = UIImage(named: "categories")
        let imageForCalendarView = UIImage(named: "calendar")

        UITabBar.appearance().tintColor = Colors.selectedTabBarItemColor
        tabBar.unselectedItemTintColor = Colors.unSelectedTabBarItemColor

        homeCoordinator.navigationController.tabBarItem = UITabBarItem(title: "", image: imageForHomeView, tag: 0)
        createTaskCoordinator.navigationController.tabBarItem = UITabBarItem(title: "", image: imageForCreateTaskView, tag: 1)
        categoriesCoordinator.navigationController.tabBarItem = UITabBarItem(title: "", image: imageForCategoriesVIew, tag: 2)
        calendarCoordinator.navigationController.tabBarItem = UITabBarItem(title: "", image: imageForCalendarView, tag: 3)

        viewControllers = [homeCoordinator.navigationController, createTaskCoordinator.navigationController, categoriesCoordinator.navigationController, calendarCoordinator.navigationController]
        self.selectedIndex = 0

    }
}

extension TabBarController: UITabBarControllerDelegate  {
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {

        guard let fromView = selectedViewController?.view, let toView = viewController.view else {
          return false 
        }

        if fromView != toView {
            UIView.transition(from: fromView, to: toView, duration: 0.3, options: [.transitionCrossDissolve], completion: nil)
        }
        return true
    }
}

这里看起来如何: enter image description here

0 个答案:

没有答案