Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save licvido/87c1eee32b90b44d0b7e2fa09ea63cc7 to your computer and use it in GitHub Desktop.
Save licvido/87c1eee32b90b44d0b7e2fa09ea63cc7 to your computer and use it in GitHub Desktop.
Present Modal ViewController when tap a TabBarItem (like camera VC in Instagram)
// 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
//
// Another article here - http://stackoverflow.com/questions/31053488/how-to-open-a-modal-with-uitabbarcontroller-and-on-close-display-last-tab-bar-v
//
@roblesrene
Copy link

In your instructions, what do you mean "has a root relation...". Do you mean make the class inherit from the UITabBarController? Also, not sure how to complete this line of code: "let cameraVC = UIStoryboard.cameraVC()..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment