How to tell if a subview was tapped twice
-
19-09-2019 - |
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.
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 UIImageVIew
and 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