iosswiftuitabbarcontrolleruimodalpresentationstyle

remove black background when switching tab of `UITabBarController`


I have UITabBarController having 4 tabs. inside the first tab's ViewController i presented Popup using popUpVC.modalPresentationStyle = .overCurrentContext

so i got this(thats perfect as i want):
enter image description here

but now when i switch to secondTab Dollor_Icon, and then immediately come back to firstTab... i get the blackBG instead of transparent BG. like this:
enter image description here

my code of modal presentation:

let popUpVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PopUp")
popUpVC.modalPresentationStyle = .overCurrentContext
self.present(popUpVC, animated: true)

Hope to get rid of that black background and why is this happening?
Thanks!


Solution

  • Add this to your firstTabViewController ViewDidLoad() method:

        definesPresentationContext = true
    

    Hope, your problem being fixed.

    For more details on definesPresentationContext see https://developer.apple.com/documentation/uikit/uiviewcontroller/1621456-definespresentationcontext'