How can I detect touch events on a UIImageView inside a deep hierarchy of UIViews?

I am developing a simple game on the iPhone, and I started with a View-based application, and through I UIViewControllerload a custom UIViewone that contains several more UIViewand some UIImageViews. I want to detect touch events on some of UIImageViews, but so far I have not been able to.

I created a second project for testing and realized that it UIImageViewhandles touch events when the hierarchy is similar:

UIViewController→ UIView→ UIImageView,

but when you like it:

UIViewController→ UIView→ UIView→UIImageView

they are not detected.

Notes:
 - userInteractionEnabled YESin all cases
 - all UIViewsand UIImageViewsI mention above are user subclasses.

- , , UIImageView , ?

+3
1

. , , , , , ..

, , , "" , hitTest:withEvent:. , , , UIScrollView, (/) , , .

, , :

  • [hitTest:withEvent:] 1 NSLog, , , .
  • (, , ----) UIView recursiveDescription . , , , - ( ) .
  • , , , . , , [MyClass buttonPressed] , UIButton, , MyClass @selector(buttonPressed) / .
  • , touchesBegan:withEvent: NSLog, , .

, userInteractionEnabled!

, , .

+4

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


All Articles