Swift 获取view所在的ViewController

func getViewController() -> 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
    }

你可能感兴趣的:(Swift 获取view所在的ViewController)