在View中找到ViewController
程序员文章站
2024-01-14 22:24:28
...
extension UIView{
//返回该view所在VC
func first ViewController() ->UIViewController? {
for view in sequence(first:self.superview, next: { $0?.superview}) {
if let responder = view?.next{
if responder.isKind(of:UIViewController.self){
returnresponderas?UIViewController
}
}
}
returnnil
}
}