How to get touch event on imageView UITableViewCell?

I want to receive notifications when a user clicks or double-clicks on a View UITableViewCell image. I tried adding a subview to the imageView and using touchhesBegan: withEvent: in the subview controller, but cannot trigger the event that I was expecting. How can I do this job?

+3
source share
3 answers

In my project, I have subclassed UIImageView to add user interaction, if this can be useful, you can just take a look at the Apple code sample project "TapToZoom". In shorts, you need to enable user interaction, and only after that the UIImageView will begin to respond to touches. This is done by setting the userInteractionEnabled property:

[self setUserInteractionEnabled:YES];

then you can configure another touchhes property, for example:

[self setMultipleTouchEnabled:YES];
twoFingerTapIsPossible = YES;

, , . UIButton, . , , UIButtons tableView, .

+1

:

UIImageView . ( ).

frisky, .

View :

[self setUserInteractionEnabled:YES];

, , . .

+3

Thanks for the answers above, the work is done.

My solution: 
  subclass a UIView, override touchesBegan: withEvent: in it implementation file
  add the UIView (as subview) to cell.view and cover the position of imageView, then make the subview nearest transparent (alpha = 0.015f)
  done.
  it works fine

Note : if the alpha number is too small (0.01f), the touch event will not fire, does anyone know why?

+1
source

Source: https://habr.com/ru/post/1723641/


All Articles