标签:sequence self int skin control color round span gre
//uiview的扩展
extension UIView{
func getFirstViewController()->UIViewController?{
for view in sequence(first: self.superview, next: {$0?.superview}){
if let responder = view?.next{
if responder.isKind(of: UIViewController.self){
return responder as? UIViewController
}
}
}
return nil
}
}
override func viewDidLoad() {
super.viewDidLoad()
//调用
let mView = UIView(frame: CGRect(origin: CGPoint.zero, size:CGSize(width: 100, height: 100)))
mView.backgroundColor = UIColor.red
self.view.addSubview(mView)
//获取mView的ViewController
let vc = mView.getFirstViewController()
}
标签:sequence self int skin control color round span gre
原文地址:https://www.cnblogs.com/chenxiaopao/p/9108022.html