Suppose I have a UIView parentView and a subview childView that is rotated at some unknown angle relative to parentView. What is the most efficient way to determine if a point within parentView (I know the coordinates in parentView's coordinate system) is within a rectangle in childView's coordinate system (the rectangle is orthogonal to, but not equal to its bounds and probably not orthogonal to parentView's bounds)?
Determining if a point in a view is within a subviews bounds
How can a point be orthogonal to a rectangle? –
Sweeney
No. The rectangle is orthogonal to the subviews bounds. If it's easier, I can deal with an answer to whether the point is within the subviews bounds (not the subview's frame). –
Sternutatory
Convert the point to the subview's coordinate system and then use CGRectContainsPoint
:
CGPoint pointInSubview = [subview convertPoint:pointInSuperview fromView:superview];
if (CGRectContainsPoint(rectInSubview, pointInSubview)) {
NSLog(@"We have a winner!");
}
© 2022 - 2024 — McMap. All rights reserved.