简体   繁体   中英

(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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM