Search code examples
swiftuitabbarcontrollerbarcode-scanner

TabbarController not hiding when opening CameraController (BarCodeScanner)


I have a BarCodeScanner-viewController which I call from 3 different views. My app also has a tabbarController. Problem is, the tabbar hides from two of the viewControllers, while the third one always shows the tabbarController, while in cameraMode (barCodeScanner).

I've tried to set the ´self.tabBarController?.tabBar.isHidden = true´ in both viewDidLoad(), viewDidAppear() and viewWillAppear() and changed it to false on viewWillDisappear()

I have also tested to set 'scanner.hidesBottomBarWhenPushed = true' without result.

// 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
        }

I wan't the tabbar to be hidden in the third example too.


Solution

  • Using Push actually adds a new controller in navigationController thats why your tabbar is not hiding to hide it with new controllers overlay you need to change push with present function in Thrid example

    Replace

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

    With

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