开发者

Touches which object

开发者 https://www.devze.com 2023-02-25 09:27 出处:网络
This may seems simple for you but I would like to know which object is being touched on a view... I explain...in the viewDidLoad method, I have several objects which are created programmatically (uii

This may seems simple for you but I would like to know which object is being touched on a view...

I explain...in the viewDidLoad method, I have several objects which are created programmatically (uiimageviews, labels, buttons, etc).

Now in the touchesEnded method, I would like to know which object has been single tapped...how to?

I tried [touch self] == UIImageView开发者_JAVA百科], but it's not working...

Thanks


The - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event callback provides the information you need the touches parameter. To extract the view that got the touch use:

UIView *touchedView = [[touches anyObject] view];

You can then compare:

if (myView == touchedView) {
   // do stuff
}

More info at developer.apple.com

0

精彩评论

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