I create a UIImageView as below
imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"military_male_target_001.png"];
imageView.frame = CGRectMake(0, 0, 10, 10);
imageView.alpha = 0.5;
and I have
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {...}
in my view controller.
so far so good, the image is displayed on screen and respond to touch down event correctly which means touchesEnded method is invoked when I click inside the image.
but if I add
imageView.userInteractionEnabled = YES
then touchesEnded method won’t be invoked when I click inside the image.
but it is still invoked when I click outside the image.
can anyone tell me how userInteractionEnabled works?
thanks in advance.
The reason why it was not invoked is because you gave
imageViewpermission to capture touches. TheimageViewwill now get the touch event and not forward it on. There is no need to setuserInteractionEnabledtoYESunless you plan on creating a customUIImageViewthat handles the touch event.Documentation: