可以检查触摸位置的物体数量吗?

发布于 2024-11-15 08:31:39 字数 131 浏览 4 评论 0原文

是否可以检查某个触摸位置的物体数量? 我已经用数字标记了所有对象,但想不出它的工作方式。

基本上我想做的是将 uiimageview 添加到触摸点,但是当已经有其他 uiimageview 时,我什么也不做。

谢谢!

Is it possible to check number of objects in a certain touch location?
I have tagged all objects with a number, but couldn't think of a way it would work.

Basically what I want to do is add uiimageview to touch point, BUT when there is already an other uiimageview, I would do nothing.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菊凝晚露 2024-11-22 08:31:39

你有一个好主意可以开始。您在视图上添加的所有对象都已保存在名为 [myview subviews] 的数组中。标记它们是个好主意,因为这样您就可以使用 [myview viewWithTag: kFirstViewTag] 轻松访问它们。

因此,要回答第二部分,当您检查触摸位置时,请检查触摸位置是否与任何子视图相交。

例如:

for (UIView* view in [myView subviews]) {
   if (CGRectContainsPoint([view frame], touchPoint) {
       //do something
   }
}

我可以假设您可能不需要遍历所有子视图,因此您可以使用 for 循环循环到从 kFirstViewTagkLastViewTag 标签限制的子视图, 喜欢:

for (int i = kFirstViewTag; i <= kLastViewTag; i++) {
   UIView *view = [myView viewWithTag: i];
   if (CGRectContainsPoint([view frame], touchPoint) {
       //do something
   }
}

You've got a good idea to start. All the objects that you add on a view are already kept in an array called [myview subviews]. It was a good idea to tag them because then you can easily access them with [myview viewWithTag: kFirstViewTag].

So to answer the second part, when your checking touch locations, check if the touch location intersects with any of your subviews.

For example:

for (UIView* view in [myView subviews]) {
   if (CGRectContainsPoint([view frame], touchPoint) {
       //do something
   }
}

I can assume you probably don't need to go trough all the subviews, so you can just cycle to ones limited with tags from kFirstViewTag to kLastViewTag with for loop, like:

for (int i = kFirstViewTag; i <= kLastViewTag; i++) {
   UIView *view = [myView viewWithTag: i];
   if (CGRectContainsPoint([view frame], touchPoint) {
       //do something
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文