打开 CameraController (BarCodeScanner) 时 TabbarController 不隐藏

TabbarController not hiding when opening CameraController (BarCodeScanner)

我有一个 BarCodeScanner-viewController,我从 3 个不同的视图调用它。我的应用程序还有一个 tabbarController。问题是,在 cameraMode (barCodeScanner) 中,tabbar 隐藏了两个 viewControllers,而第三个总是显示 tabbarController。

我尝试在 viewDidLoad()、viewDidAppear() 和 viewWillAppear() 中设置“self.tabBarController?.tabBar.isHidden = true”,并在 viewWillDisappear() 中将其更改为 false

我也试过设置'scanner.hidesBottomBarWhenPushed = true'没有结果。

// working:
setUpBackButton(withTitle: NSLocalizedString("button_cancel", comment: ""))
        let scanner = BarCodeScanner()
        self.navigationController?.pushViewController(scanner, animated: true)
        scanner.callback = { result in
            // code with result
        }


// working: 
setUpBackButton()
        let scanner = BarCodeScanner()
        scanner.modalPresentationStyle = .overCurrentContext
        self.navigationController?.pushViewController(scanner, animated: true)
        scanner.callback = { result in
            // code with result
        }


// NOT WORKING (i.e. not hiding the tabbarController):
let scanner = BarCodeScanner()
        setupBackButton()
        scanner.modalPresentationStyle = .overCurrentContext
        self.navigationController?.pushViewController(scanner, animated: true)
        scanner.callback = { result in
            // code with result
        }

我也不想在第三个示例中隐藏标签栏。

使用 Push 实际上在 navigationController 中添加了一个新控制器,这就是为什么你的标签栏没有隐藏以使用新控制器覆盖隐藏它你需要在 Thrid 示例中使用现有功能更改推送

替换

self.navigationController?.pushViewController(scanner, animated: true)

self.navigationController?.present(scanner, animated: true, completion: nil)