In the project, there are an UIView
myView and an UIImageView
myImage behinds the myView, views hierarchy:
UIWindow
|-- UIImageView (myImage)
|-- UIView (myView) [whole screen]
Then added a gesture recognizer to myImage in ViewController
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
tapGesture.numberOfTapsRequired = 1;
[myImage addGestureRecognizer:tapGesture];
But gesture doesn't affect myImage, myImage has setUserInteractionEnabled:YES
. It will only affect when myImage placed in front of myView, how can I solve this problem?
Your
UIView
obviously intercept the touches before they can reach theUIImageView
.You can either put your
UIImageView
in front of yourUIView
, or disable user interaction on theUIView
so it does not intercept the touches.If you need finer grain over catching your touch events, you may either:
UIView
on top of theUIImageView
if it has to for design purposes (if it masks theUIImageView
a bit for example) but make it not catch events (userInteractionEnabled = NO
), and use a differentUIView
below theUIImageView
to actually catch the events outside theUIImageView
UIView
on top of theUIImageView
and keep it catching events (userInteractionEnabled = YES
), but filter the events that pass thru it, by subclassing yourUIView
and overriding either thepointInside:withEvent:
or thehitTest:withEvent:
method.For more information you should really read the dedicated Apple Programming Guide related to Event Handling.
my code:
two properties are neccessary to do
1.) add the GestureRecognizer to your UIImageView (self.DGEMLogo) [self.DGEMLogo addGestureRecognizer:press];
2.) set your UIImage property Interaction enabled to TRUE
thats all.