I have a UIView , and the user can click UIView on "select" or select the "thing" in the application that it represents. To achieve this, I use CGRectContainsPoint(thing.frame,tapPoint) , where thing.frame is a UIView frame and tapPoint is a point with a point from UITapGestureRecognizer . It works great.
.. unless the UIView rotated by setting the transform property (with a value of CGAffineTransform ). When the UIView rotates like this, frame becomes a flat square that encapsulates the rotated view.
Here is an illustration of the problem (the frame property is marked as A, and the visual UIView bounds indicated by B):
When NOT rotated
+
During rotation
+-----------------+ | A . | | . . | | . . | | . . | | . B . | | . . | | . . | | . | +-----------------+
I want to capture cranes that are within rect B (true UIView borders UIView rotated), but NOT when they are only within rectangle A (the value of the frame property is UIView ), and not B
How can I calculate if a given transition point is within the true borders / frames / borders of the rotated UIView ? Is there a convenience method for this? Or do I need to calculate the coordinates and dimensions of B using my own geometry?
(If the latter, please include a sentence so that we can make the answer as complete as possible. Thank you!)
source share