Get top most UIViewController

后端 未结 24 1906
别那么骄傲
别那么骄傲 2020-11-22 14:47

I can\'t seem to get the top most UIViewController without access to a UINavigationController. Here is what I have so far:

UIApplic         


        
24条回答
  •  逝去的感伤
    2020-11-22 15:23

      var topViewController: UIViewController? {
            guard var topViewController = UIApplication.shared.keyWindow?.rootViewController else { return nil }
            while let presentedViewController = topViewController.presentedViewController {
                topViewController = presentedViewController
            }
            return topViewController
        }
    

提交回复
热议问题