开发者

Passing Touch Events

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开发者_StackOverflow 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.


The nextResponder of a view is either its view controller or its superview. The UIButton in your setup is neither, so it doesn't receive the events.

In this situation, instead of forwarding the events to the nextResponder you should override pointInside:withEvent: to return NO. That way the system will act like your view isn't even there. According to the documentation, you could also set userInteractionEnabled to NO on your view for the same effect.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜