Search code examples
swifttabbar

Swift: Tabbar cannot be hidden with imagePickerController


People please help I am desperate... :-(

I am having a tabbar with 4 items....I will execute this to get modal view over the tabbar.

self.tabBarController?.tabBar.isHidden = true
self.tabBarController?.tabBar.layer.zPosition = -1
let modal = self.storyboard?.instantiateViewController(withIdentifier: "NewTripVC") as! NewTripVC
let navigationController = UINavigationController(rootViewController: modal)
navigationController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(navigationController, animated: true, completion: nil)

In that modal I have an image view that can contain a photo...I am picking the image from photo library with image picker

var imagePicker = UIImagePickerController()

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum){
   self.imagePicker.delegate = self
   self.imagePicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum;
   self.imagePicker.allowsEditing = false
   self.imagePicker.navigationBar.isTranslucent = false
   self.present(self.imagePicker, animated: true, completion: nil)
}

And then I am using this for closing....but when the view is closed...tab bar will popup and I can't hide it :-(

//this will dismiss the view but also will show tabBar that can't be hidden with any way
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
   imagePicker.dismiss(animated: true, completion: nil)
}

I tried this... but this does not working...:

self.tabBarController?.tabBar.isHidden = true
self.tabBarController?.tabBar.layer.zPosition = -1

enter image description here


Solution

  • Well the answer is very simple. Change

    navigationController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
    

    To this.....so lame

    navigationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen