触摸开始于特定对象

发布于 2024-09-14 21:18:28 字数 231 浏览 5 评论 0原文

我一直在谷歌上搜索,但没有找到任何答案。

我想在特定对象上使用 TouchesBegan,例如文本视图、标签...... 我尝试用我的对象的指针替换“任何对象”,但它不起作用。

是否有其他方法可以用某种方法检测物体上的触摸,以便我可以告诉:做某事? ,就像在 TouchsBegan 方法中一样,但是针对特定对象?

提前感谢您的回答/或者示例代码会很棒;o)祝您

有美好的一天! 罗宾

I've been searching on google for that , but didn't found any answer.

I want to use TouchesBegan but on a specific object, like a textview, a label, ...
I've tried to replace "any object" by the pointer of my object but it doesn't work.

Is there on other way to detect the touch on a object with a method , in witch I can tell after : do something ? , like in the touchesbegan method but for a specific object ?

Thank you in advance for your answers / or sample code would be great ;o)

Have a nice day !
Robin

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

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

发布评论

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

评论(2

暮色兮凉城 2024-09-21 21:18:28

通过 CGRectMake() 在该区域上创建 CGRect,然后检查触摸是否在该区域内 - 然后执行您的操作。

// sample code inside Touchesbegan method
CGRect tempRect = CGRectMake(x, y, width, height);
if (CGRectContainsPoint(tempRect, touchlocation)) 
{
    // do some thing
}

Make CGRect by CGRectMake() on that area and then check, if touch is within that area - then do your things.

// sample code inside Touchesbegan method
CGRect tempRect = CGRectMake(x, y, width, height);
if (CGRectContainsPoint(tempRect, touchlocation)) 
{
    // do some thing
}
三人与歌 2024-09-21 21:18:28

我不确定我是否完全理解您的要求,但是如果您对要检测触摸的对象类进行子类化并向该类添加 TouchBegan 方法,则只有当其所属的对象被触摸时才会触发它。我相信这就是您正在寻找的。

或者你问的是不同的东西?
霍华德

I'm not sure I understand exactly what you're asking, but if you subclass the class of object you want to detect touches on and add a touchesBegan method to that class, it will only get triggered when the object it belongs to is touched. Which I believe is what you're looking for.

Or are you asking something different?
Howard

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文