3

I have a bunch of UIViews stacked one upon the other(not nested). I want them all to react to touch, but it seems that the topmost view obscures the views beneath it, preventing them from receiving touch events.

At first i thought i’d catch all touch events with the topmost view, and then manually call
hitTest, or pointInside methods on all the underlying views, but i found out that both methods are somehow private(could it be?) and cannot be accessed.

Any ideas how to pull it off?

4

2 回答 2

3

您可以检查触摸是否适用于您的最顶层视图。如果不是,您可以调用您的超级视图的相同方法。类似于 [self.superview sameMethod:sameParameter]。

你最顶层的视图有一个方法

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

在该方法中,您的逻辑正确吗?在方法内部,您不能检查收到的触摸是否在您的最顶层视图中

UITouch *touch = [touches anyObject];
[touch locationInView:self];

如果没有,你将它传递给 superView 的相同方法,使用

[self.superview touchesEnded:touches withEvent:event];
于 2011-01-03T14:12:10.113 回答
3

触摸被发送到单个视图。然后,该视图可以选择将它们传递给响应者链。如果您想处理对一组视图的触摸,您应该让它们将这些事件转发给下一个响应者,并让它们有一个共同的父级(或它们的视图控制器,因为控制器也是响应者链的一部分)处理这些触及。

https://developer.apple.com/library/mac/documentation/General/Devpedia-CocoaApp-MOSX/Responder.html

于 2011-01-03T19:18:48.477 回答