开发者

TouchesBegan on specific object

开发者 https://www.devze.com 2023-01-11 10:07 出处:网络
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 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


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
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消