Search code examples
swifttouchesbegan

(Swift) - touchesBegan called more than once


I would like to detect a tap on a subview by implementing touchesBegan but the issue is that this function is called multiple times for 1 touch. Actually, it is called the number of times that there is view/subviews where I touch the screen, but in my case I only want to detect the subview I touch but not the superviews.

For that, I have also used "pointInside" and "hitTest" but without success. What is strange is that, even if touchesBegan is called the number of times I have view/subviews, it always return the last subview...

Is it normal ?

Thanks :)


Solution

  • If you have multiple views and userInteractionEnabled property is true, you are getting touchesBegan for each view.

    You have to change userInteractionEnabled = NO in your subview.