Collision detection on sub views contained in 2 se

2019-06-05 00:32发布

问题:

I originally setup some conditions using CGRectIntersectsRect for some collision detection which worked fine. In the greater scale of things I only need part of the view to be detected.

So originally within the ViewController it was comparing 2 UIviews.

Now what I need to do is collision detection of subViews within 2 different UIViews that are contained in a view in which the view controller does the logic.

My script is no longer working as I suspect CGRectIntersectsRect only compares frames within the same view? I'll keep digging to confirm this.

Any ways around this? Is it possible for example to get the x and y pos of the sub view in relation to the main view that's performing the logic?

回答1:

You'll need to use UIView's convertRect:toView: or convertRect:fromView: (or the point equivalents) to get them in the same coordinate space.