Collision detection on sub views contained in 2 separate parent UIViews?

倖福魔咒の 提交于 2019-12-08 07:17:23

问题


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.



来源:https://stackoverflow.com/questions/2530757/collision-detection-on-sub-views-contained-in-2-separate-parent-uiviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!