Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. static var topMostViewController: UIViewController {
  2. var viewController: UIViewController = (UIApplication.shared.keyWindow?.rootViewController)!
  3.  
  4. while (viewController.presentedViewController != nil){
  5. viewController = viewController.presentedViewController!
  6. }
  7.  
  8. return viewController
  9. }
  10.  
  11. static var currentViewController: UIViewController? {
  12. if let tabBarController = UIViewController.topMostViewController as? UITabBarController {
  13. if let navigationController = tabBarController.selectedViewController as? UINavigationController {
  14. return navigationController.viewControllers.first
  15. } else {
  16. return tabBarController.selectedViewController
  17. }
  18. } else if let navigationController = UIViewController.topMostViewController as? UINavigationController {
  19. return navigationController.viewControllers.first
  20. } else {
  21. return UIViewController.topMostViewController
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement