-
-
Save wavecos/4dcb1410a41b9dd521cb to your computer and use it in GitHub Desktop.
// 1. First Create a Dummy UIViewController that has a root relation with the UITabBarController | |
// 2. Make this controller implement a UITabBarControllerDelegate | |
// 3. In ViewDidLoad: | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.tabBarController?.delegate = self | |
} | |
// 4. Implement this delegate method: | |
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) { | |
let isModalTab = viewController == self | |
if isModalTab { | |
let cameraVC = UIStoryboard.cameraVC() // 5. HERE YOU SPECIFY THE MODAL VIEW CONTROLLER!!! | |
self.presentViewController(cameraVC, animated: true, completion: nil) | |
} | |
} | |
// 5. That's all | |
@mdabrarniyazi , here is a way to do what you want...
MyTabBarController: UITabbarComtroller, UITabbarControllerDelegate {
// setup your view controllers as usual
// created the tab bar item for the view you want to present modally
// In viewDidLoad()
let cameraVC = CameraViewController()
cameraVC.tabbarItem = UITabbarItem(title: "Camera", image: cameraImage)
viewControllers = [vc1, vc2, cameraVC, vc4, vc5]
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
let isModalView = viewController is CameraController
if isModalView {
// you can refactor this part of the code
let cameraController = UINavigationController(rootViewController: CameraController())
self.present(cameraController, animated: true, completion: nil)
return false
} else {
return true
}
}
}
For this to work properly, the delegate method has to be implemented in the first viewController that would show on the UITabBarController.
Additionally, after stopping receiving tapGesture for your popup tab item you have to implement custom presentation style of popup viewcontroller inside the tabBarController didSelect func, otherwise it does not seem to work.
But with this method if you dismiss the presented view then you come back to dummy view. In other apps you go to previous view.