简体   繁体   中英

Tap Gesture Recognizer In Bounds

Is it possible to check whether a tap gesture occurred within certain bounds of an object? For instance, I have a custom drawn view with three triangular sections. I want to know if the gesture sent from the tap gesture recognizer occurred within triangle 1, 2, or 3.

You can use sender.locationInView(nameOfYourView) in the action for your gesture recognizer to retrieve a location of the tap. Check if this point is in the bounds of each triangle to find out if it is in the triangle (I don't know your implementation of the triangles so I can't answer how to do this. Are they each separate views? Are they just part of an image? Did you draw them via CALayer or UIBezierPath?).

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