4

I have a working UIButton in my view controller's view.

I have a UIView instance on top of the button (I'll refer to it as topView) in the same view controller's view. If a condition is met I am forwarding all of the touch events (began, moved, ended, canceled) to the view's nextResponder.

But when the condition is triggered, the button is not receiving the event. If I move the topView so it is not over the button, the button works (or set the userInteractionEnabled property to false). If topView is over the button, the button does not work. So frustrating because I can see the button under the view!

Do I have to do anything in the view controller to receive the touch events from sending them to the nextResponder?

I have read all the documents I can on the Responder Chain, but I am still a bit confused.

4

1 回答 1

6

视图的 nextResponder 要么是它的视图控制器,要么是它的父视图。您设置中的 UIButton 两者都不是,因此它不接收事件。

pointInside:withEvent:在这种情况下,您应该重写以返回 NO ,而不是将事件转发给 nextResponder 。这样,系统就会表现得好像您的视图不存在一样。根据文档,您还可以在视图上将 userInteractionEnabled 设置为 NO 以获得相同的效果。

于 2011-03-01T03:50:19.423 回答