I know that a lot of threads are opend for this problem but yet, I haven't found a solution for this problem.
Code:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// We only support single touches, so anyObject retrieves just that touch from touches
UITouch *touch = [[event allTouches] anyObject];
if ([touch tapCount] == 2) {
//Do A
}
// In case of a double tap outside the placard view, update the placard's display string
else if ([touch tapCount] == 1) {
//DO B
}
}
and he said there that this is the behavior... what does he means ?
95% of all the posts use the 'tapCount'.
I've even try to use:
UIControlEventTouchDownRepeat & UIControlEventTouchUpInside, with IBActions, and always the UIControlEventTouchUpInside call first...
I personally add a BOOL. I make it something like tappedTwice. I set it equal to YES once I enter the double count and I set up the single count to not run if tappedTwice is equal to YES. I have the value reset to NO once I know I can again. Without looking at my code, this is how I do it:
Code:
BOOL tappedTwice = NO;
if ([touch tapCount] == 2) {
tappedTwice = YES;
//whatever here
}
else if ([touch tapCount] == 1 && !tappedTwice) {
//whatever here
}
}
If it is setup as a local BOOL, then you do not have to worry about setting it back to NO. This works for me, hope it works for you.
Setting a boolean is a bit kludgey, and will be hard to maintain for other tap situations (triple, quadruple, etc). There actually IS an "official" way to handle this situation described in the documentation. It's described, but Apple does not give sample code.
How you handle it is to call the correct method in each case using performSelector:withObject:afterDelay:, then, in each situation except single-tap, cancel the previous call before it executes (double-tap cancels the single-tap call, triple-tap cancels the double-tap call). This is what it might look like:
That sounds great but I want to be able to send the event and the touch to the singleTap method since this will forward it if necessary to another responder. I cannot do this with this solution.
I have tried using a timer but there seems to be a problem. Can anybody tell me what might be wrong.
This successfully calls the singleTapMethod and when looking at the debugger the objects passed are the same (location wise) but when calling [super touchesBegan:withEvent] on this method it does not handle it at all. Nothing happens. If I just implement the [super touchesBegan:withEvent] on the touchesBegan method it successfully handles it by forwarding it.
BTW already tried using self.nextResponder to try and force it myself to forward the touchesBegan but it won't work either.
Edit:
I did some more research and although the touch and event do get forwarded, when getting to the touchesBegan on the subview they have been forwarded to the reason they don't work is because getting the coordinates and/or the tapCount returns cero for the touch. Can anybody please shed some light on this situations?
Setting a boolean is a bit kludgey, and will be hard to maintain for other tap situations (triple, quadruple, etc). There actually IS an "official" way to handle this situation described in the documentation. It's described, but Apple does not give sample code.
How you handle it is to call the correct method in each case using performSelector:withObject:afterDelay:, then, in each situation except single-tap, cancel the previous call before it executes (double-tap cancels the single-tap call, triple-tap cancels the double-tap call). This is what it might look like: