views:

106

answers:

2

I have a UIImageView that I allocated inside of a UIView. I want to double tap that subview using the TOUCHESENDED or TOUCHESBEGAN and send a callback or at least a log. I would appreciate anyone who can upload some code.

A: 

As per the documentation, it is not recommended to subclass UIImageView, but this is for drawing, if you only want to catch events, you may subclass UIImageVIewand catch the event. Then look at the tapCount property of the touch. As per http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UITouch_Class/Reference/Reference.html#//apple_ref/occ/instp/UITouch/tapCount

I don't know why, but I can't put that link not inline, it display correctly in JS preview, but not on the page.
I actualy ended up initializing it as another king of view, then making a file to control that then put the touchesBegan method inside that .m file. Thanks
Jaba
+1  A: 

Here's how to use the .tapCount property inside touchesBegan:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
{
 NSUInteger numTaps = [[touches anyObject] tapCount];
 UITouch *touch = [[event allTouches] anyObject];

 if ([touch view] == yourThing) {
   NSLog(@"%i taps", numTaps);
 }
}
willc2
but what I am taping is a subview of my Super and I want to ask my subView how many times it's been tapped
Jaba
This will print how many times a specific view has been touched.
willc2