Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-10-2008, 08:16 AM   #4 (permalink)
jeff_lamarche
New Member
 
Join Date: Apr 2008
Posts: 420
Send a message via AIM to jeff_lamarche Send a message via Yahoo to jeff_lamarche
Default

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:


Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
	NSUInteger tapCount = [touch tapCount];
	
	switch (tapCount) {
		case 1:
			[self performSelector:@selector(singleTapMethod) withObject:nil afterDelay:.4];
			break;
		case 2:
			[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod) object:nil];
			[self performSelector:@selector(doubleTapMethod) withObject:nil afterDelay:.4];
			break;
		case 3:
			[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doubleTapMethod) object:nil];
			[self performSelector:@selector(tripleTapMethod) withObject:nil afterDelay:.4];
			break;
		case 4:
			[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(tripleTapMethod) object:nil];
			[self quadrupleTap];
			break;
		default:
			break;
	}

}
@end
__________________
Check out my iPhone Dev Blog
You can send me e-mail at my forum username at mac dot com.
jeff_lamarche is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,818
Threads: 89,206
Posts: 380,632
Top Poster: BrianSlick (7,129)
Welcome to our newest member, katearmine
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.