Created
February 14, 2019 03:34
-
-
Save orangeince/9ff71ec2cab5a578ed7ab74333532dd8 to your computer and use it in GitHub Desktop.
记录一些iOS里方便的扩展方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: UIViewController | |
extension UIViewController { | |
static var topMost: UIViewController? { | |
var top = UIApplication.shared.keyWindow?.rootViewController | |
while true { | |
if let presented = top?.presentedViewController { | |
top = presented | |
} else if let nav = top as? UINavigationController { | |
top = nav.visibleViewController | |
} else if let tab = top as? UITabBarController { | |
top = tab.selectedViewController | |
} else { | |
break | |
} | |
} | |
return top | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment