How to tell if a subview was tapped twice
I have a UIImag开发者_Python百科eView 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.
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);
}
}
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
精彩评论