I am doing an iPad app. How do I send touch events to its superview?
I am adding a view which is always some other activity. On that I am adding scrollview to half the screen and in the other half I add another view. It all works fine, now I want to add a button and a small description view that will appear when button is tapped and disappear again when button is tapped again. In order to implement this I took a view which covers the entire view and made its back ground color clear. I place this button and description view into this view but it wont scroll because of transparent view.
I want to make this transparent view ignore its events.
Can this be done?
Top voted solution was not fully working for me, it was in fact passing along touches to some parts of the UI but it was messing with my tableView intercepting touch events, what finally did it was overriding hitTest in the view I want to ignore touches (that would be your transparent view) and let the subviews of that view handle them (that would be your button)
Set the view's
userInteractionEnabled
property toNO
. This lets all touches through to the view behind it.You can set it in the interface builder/storyboards in the attributes inspector, or in code:
For when you have a transparent view with a button in it:
Make a subclass of that view and override the
pointInside
method. The way I do it, is to give the button's frame to the subclass as a property, to check for in thepointInside
method:Hope it helps!