可以检查触摸位置的物体数量吗?
是否可以检查某个触摸位置的物体数量? 我已经用数字标记了所有对象,但想不出它的工作方式。
基本上我想做的是将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有一个好主意可以开始。您在视图上添加的所有对象都已保存在名为
[myview subviews]
的数组中。标记它们是个好主意,因为这样您就可以使用[myview viewWithTag: kFirstViewTag]
轻松访问它们。因此,要回答第二部分,当您检查触摸位置时,请检查触摸位置是否与任何子视图相交。
例如:
我可以假设您可能不需要遍历所有子视图,因此您可以使用 for 循环循环到从
kFirstViewTag
到kLastViewTag
标签限制的子视图, 喜欢: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:
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
tokLastViewTag
with for loop, like: