Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top