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.

Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58
  • So, I just confirmed that my view controller is receiving the forwarded touch messages I am sending to nextResponder. But the buttons in the view controller's view do not. What do I have to do to pass the events to the button in the view controller's view? – Jeshua Lacock Mar 01 '11 at 04:04

1 Answers1

6

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.

Anomie
  • 92,546
  • 13
  • 126
  • 145
  • I can't set userInteractionEnabled to NO, because parts of my view have to respond to touch. I have to pass the touch where my topView is transparent, but for design reasons, the view has to be full screen which covers the lower UI elements such as my buttons. Overide pointInside:withEvent in my UIButton or the topView? – Jeshua Lacock Mar 01 '11 at 04:21
  • Cool! Overriding pointInside:withEvent: in the topView totally works! Thanks a million! Guess this is a case of me trying to hard! – Jeshua Lacock Mar 01 '11 at 08:20
  • p.s. Tried to vote your answer up, but apparently I am too noob! – Jeshua Lacock Mar 01 '11 at 08:21
  • Glad it worked. You should be able to "accept" the answer by clicking on the check box outline to the left of the answer. – Anomie Mar 01 '11 at 11:59