确定视图中的某个点是否在子视图范围内

Vic*_*gel 7 rectangles subview uiview bounds ios

假设我有一个UIView parentView和一个子视图childView,它以相对于parentView的某个未知角度旋转.确定parentView中的一个点(我知道parentView的坐标系中的坐标)是否在childView的坐标系中的矩形内是最有效的方法(矩形是正交的,但不等于它的边界,可能与parentView的正交不正确)界)?

rob*_*off 20

将点转换为子视图的坐标系,然后使用CGRectContainsPoint:

CGPoint pointInSubview = [subview convertPoint:pointInSuperview fromView:superview];
if (CGRectContainsPoint(rectInSubview, pointInSubview)) {
    NSLog(@"We have a winner!");
}
Run Code Online (Sandbox Code Playgroud)