I defined a UIview as an overlay view:
self.disableViewOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0f,44.0f,320.0f,416.0f)];
self.disableViewOverlay.backgroundColor=[UIColor blackColor];
self.disableViewOverlay.alpha = 0;
Now I would like to disable the overlay view if a user taps on it…
[disableViewOverlay removeFromSuperview];
How do I find out if the user taps on this overlay view? Is there a “tapped” method just like a button has an IBAction?
Thanks!
You have two options:
overriding
hitTestin yourUIView;overriding
touchesBegan:withEvent:,touchesMoved:withEvent:,touchesEnded:withEvent:for greater control.Both approaches require that you subclass your
UIView(the one you want to detect the tap on).Have a look at UIView Class Reference or UIResponder Class Reference respectively.
If you do not want to subclass your
UIView, another option is attaching it to aUITapGestureRecognizer:you would then disable the overlay in the
handleTapOnViewfunction.Gesture recognizers are available only from iOS 3.2 on.
Check this: UITapGestureRecognizer Class Reference