1

I have an overlay view that covers up many sibling views (buttons).

I am trying to forward touches to a sibling view that is underneath the overlay view using this answer here: https://stackoverflow.com/a/4847478

This is because my overlay view has GestureRecognisers.

I would like the overlay view to be able to recognise gestures (including gestures over buttons) AND pass all touch events to sibling views beneath it.

I have discovered that the events do get forwarded, but the button clicks are still not triggered, perhaps due to the fact that the touches are owned by the overlay view.

I do not think it is possible to change ownership of the touch.

How can I get the button clicks to register, given that the events are actually being forwarded?

Community
  • 1
  • 1
ignoramus
  • 111
  • 4
  • Where is your button added ? on overlay or below overlay ? – CodeChanger Mar 08 '17 at 09:57
  • @CodeChanger below the overlay; the (transparent) overlay covers up the buttons. – ignoramus Mar 08 '17 at 09:59
  • Is your overlay transparent? It may be that you do not want an overlay, but in fact just want to add you gesture recogniser to the super view of your buttons, you can then implement it's delegate to allow other recognisers to recogniser simultaneously with it. If this sound like a solution for you, let me know and I can provide a more detailed solution? – George Green Mar 08 '17 at 11:44
  • @GeorgeGreen Yes, I don't need the overlay view. I need all gestures to be recognised on the SuperView, and to pass on the touches to the buttons even if a gesture has been recognised. I have IBActions connected to the TouchUpInside events of the buttons. Right now, even though the buttons are getting the touchesBegan,touchesMoved, etc calls, the TouchUpInside event is not firing. I don't want to implement a custom detection of TouchUpInside. – ignoramus Mar 08 '17 at 22:28
  • @ignoramus Interesting, if you have removed the overlay and moved the gesture recognisers to the super view, then it should play ball with the other controls. Could you post the controller code that is causing the issue and we should be able to sort this out? – George Green Mar 08 '17 at 22:34
  • @GeorgeGreen Yes, it works. Thank you very much! Could you post your comment as an answer so I can accept it? – ignoramus Mar 09 '17 at 00:18

1 Answers1

0

For your issue you have to Pass your responder to next level if its alpha value is 0 and based on that it will pass your responder message to next view and by this you can get your touch or click on Button.

Override pointInside: method in your container view and check if touched view alpha is 0 than pass return NO for pass message to next responder.

like this :

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    for (UIView *view in self.subviews) {
        if (!view.hidden && view.alpha > 0 && view.userInteractionEnabled && [view pointInside:[self convertPoint:point toView:view] withEvent:event])
            return YES;
    }
    return NO;
}

Hope this will helps you to understand responder chain For more detail you can check this accepted answer : How can I click a button behind a transparent UIView?

Community
  • 1
  • 1
CodeChanger
  • 7,953
  • 5
  • 49
  • 80
  • Unfortunately that will not work, as I need the gesture to be recognised on the overlay view, regardless of whether the touch was on a button or not. – ignoramus Mar 08 '17 at 10:20
  • But as per your question you need button event not gesture recognizer event on button am i right ? – CodeChanger Mar 08 '17 at 10:26
  • Ok I've just tried it, and it doesn't work. I need gesture recogniser event on ALL of the overlay view, including over the buttons. I have edited the question to clarify this. – ignoramus Mar 08 '17 at 10:37
  • Ok so one more thing you can do in that case detect button in gesture recognizer but for that can you post some code so we can get idea how you are using button and gesture in your view? – CodeChanger Mar 08 '17 at 10:51