Swift view 中 獲取ViewController

weixin_34320159發表於2018-10-18
///擴充套件中的方法
extension UIView {
    var getCurrentVC: UIViewController? {
        var next = superview
        while (next != nil) {
            let nextResponder = next?.next
            if (nextResponder is UIViewController) {
                return nextResponder as? UIViewController
            }
            next = next?.superview
        }
        return nil
    }
}

相關文章