Skip to content

Instantly share code, notes, and snippets.

@orangeince
Created February 14, 2019 03:34
Show Gist options
  • Save orangeince/9ff71ec2cab5a578ed7ab74333532dd8 to your computer and use it in GitHub Desktop.
Save orangeince/9ff71ec2cab5a578ed7ab74333532dd8 to your computer and use it in GitHub Desktop.
记录一些iOS里方便的扩展方法
// 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