对2个单独的父UIView中包含的子视图进行碰撞检测? [英] Collision detection on sub views contained in 2 separate parent UIViews?

查看:68
本文介绍了对2个单独的父UIView中包含的子视图进行碰撞检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初使用CGRectIntersectsRect设置了一些条件,以进行一些碰撞检测,但效果很好.在更大范围内,我只需要检测部分视图即可.

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.

因此,最初在ViewController中,它是在比较2个UIview.

So originally within the ViewController it was comparing 2 UIviews.

现在我需要做的是在视图控制器执行逻辑的视图中包含的2个不同UIView中对subView进行冲突检测.

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.

我的脚本不再起作用,因为我怀疑CGRectIntersectsRect仅比较同一视图中的帧?我会继续挖掘以确认这一点.

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

有什么办法解决吗?例如,是否有可能获得子视图相对于执行逻辑的主视图的x和y pos?

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?

推荐答案

您需要使用UIView的convertRect:toView:convertRect:fromView:(或等价点)来将它们放置在相同的坐标空间中.

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

这篇关于对2个单独的父UIView中包含的子视图进行碰撞检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆