开发者

How can I prevent clipped portions of subviews from still taking touch events?

开发者 https://www.devze.com 2023-04-07 01:22 出处:网络
I\'m currently clipping some UIViews w开发者_StackOverflow社区ithin a parent view like in the illustration below:

I'm currently clipping some UIViews w开发者_StackOverflow社区ithin a parent view like in the illustration below:

How can I prevent clipped portions of subviews from still taking touch events?

The problem is that the clipped portions (the invisible portions) of the subviews are still receiving touch events that, intuitively, should be going to the other views visible there.

Is there something else I should be doing to achieve this behavior, or is this not actually an easy thing to do?


This was happening because the parent view in this case had a custom implementation of

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event,

and it wasn't performing this bounds test (which I now assume is part of the default implementation).

Adding:

if ([self pointInside:point withEvent:event]) {
    ....
}

around the code in that implementation solved the problem.

0

精彩评论

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