I am trying to make a dimming view like what in UISearchDisplayController, which capture tap gesture to cancel search.
I found in debugger that the UISearchDisplayController just add a private dimmingView which is an instance of UIControl as the searchContentsViewController, and the dimming capture all touch events even a UIButton is on the searchContentsViewController actually under the dimmingView.
in my demo code(test in iOS SDK 5.0) , I subclass a @interface DimmingView:UIControl. if i just click in the bounds of the Button under dimming view, the button catch event and the dimming view catch nothing, even I’ve overridden the touchesBegan, sendAction,… methods. And if the click point is out of the button bounds , my dimming view catch events while the super view of both the button and dimming view catch nothing.
then how does UISearchDisplayController’s dimming view approach the effect that prevent the under views, event button, get the touch event?
Your dimming view needs to have user interaction enabled –
And typically a tap gesture recogniser to pick up when it is tapped.
This will capture touches from anything that is underneath it. If you add further subviews on top of the dimming view, then they will be touchable.