开发者

How to receive all touch events that occur in a view hierarchy?

开发者 https://www.devze.com 2023-02-19 17:30 出处:网络
I have a complex view hierarchy controlled by an UIViewController. I\'m looking for a simple way to inform the controller about all touches happening inside the hierarchy, even those that are handled

I have a complex view hierarchy controlled by an UIViewController. I'm looking for a simple way to inform the controller about all touches happening inside the hierarchy, even those that are handled by subviews. I don't want to intercept them, I just want to be informed开发者_运维问答 about them.

And subclassing all views in the hierarchy is not really an option.

Thanks!


Subclass root view in your controller and implement hitTest:withEvent: method in it:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    UIView *result = [super hitTest:point withEvent:event];
    // Your custom code
    return result;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消