title: how to get the currently displayed controller in anywhere
body: <p>I need to get the currently displayed controller anywhere, but all the information points to the following method </p>
  
  <pre><code>// 获取当前显示的Controller
  + (UIViewController *)currentViewController {
      // Find best view controller
      UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
      return [self findBestViewController:viewController];
  }
  
  + (UIViewController*)findBestViewController:(UIViewController*)vc {
      if (vc.presentedViewController) {
          return [self findBestViewController:vc.presentedViewController];
      } else if ([vc isKindOfClass:[UISplitViewController class]]) {
          UISplitViewController* svc = (UISplitViewController*) vc;
          if (svc.viewControllers.count &gt; 0)
          return [self findBestViewController:svc.viewControllers.lastObject];
          else
          return vc;
      } else if ([vc isKindOfClass:[UINavigationController class]]) {
          UINavigationController* svc = (UINavigationController*) vc;
          if (svc.viewControllers.count &gt; 0)
          return [self findBestViewController:svc.topViewController];
          else
          return vc;
      } else if ([vc isKindOfClass:[UITabBarController class]]) {
          UITabBarController* svc = (UITabBarController*) vc;
          if (svc.viewControllers.count &gt; 0)
          return [self findBestViewController:svc.selectedViewController];
          else
          return vc;
      } else {
          return vc;
      }
  }
  </code></pre>
  
  <p>The obtained controller is no problem to jump, such as push and present. But if I need to know the class of the currently displayed controller, if the current controller contains sub-controllers, I ca n’t know which one is currently displayed, causing the requirements corresponding to my page and popup to be unrealizable</p>