iOS事件传递链, 响应链

2021-06-06  本文已影响0人  lieon

传递链

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool
事件传递流程

响应链

响应传递示例

应用

extension UIView {
    var viewController: UIViewController? {
        var next = next
        var current: UIViewController?
        while next != nil {
            if next is UIViewController {
                return next as? UIViewController
            }
            next = next?.next
        }
        return current
    }
}
上一篇 下一篇

猜你喜欢

热点阅读