在另一个子视图之上检测一个子视图 [英] detect one subview on top of another subview

查看:127
本文介绍了在另一个子视图之上检测一个子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在另一个子视图上拖动时检测到一个子视图,看它是否发生碰撞。有什么好办法呢?我正在使用UIPanGestureRecognizer来拖动元素。谢谢

I am trying to detect one subview when dragged on top of another subview to see if it collides. What is a good way to do that? I am using UIPanGestureRecognizer for dragging the elements. thanks

推荐答案

您可以使用 CGRectIntersectsRect()执行以下任务:

You can use CGRectIntersectsRect() for doing the task:

if(CGRectIntersectsRect(firstSubview.frame, secondSubview.frame))
{
   //collides, do your task here
}

这篇关于在另一个子视图之上检测一个子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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