Before writing a simple picture viewer, click on the image in the picture, double-click on event handling encountered problems, by delaying the event action.
Method One:
Details: 1. Set global variables
BOOL Doubletap;
Set the delay action in the Click event method
To delay when clicked:
Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.2 * nsec_per_sec)), Dispatch_get_main_queue (), ^{ if (Doubletap = = YES) return; Click the related action of the event });
When it is double-clicked:
Doubletap = YES;
This will not be done after 0.2 seconds of the operation of the single-machine event, perform a double-click operation, remember to set ( doubletap =NO )
When the event is double-clicked:
Click event Action after 0.2 seconds
-------------------------------------
Method Two : (at NetEase interview, then discussed this question, I said own method, Daniel gave me two methods-only to say Daniel is Daniel)
[Self performselector: @selector (Test) Withobject:nil afterdelay:.2]; [NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (test) Object:nil];
The above two simple means, a delay operation, one is to cancel the delay operation, through this to control the single-machine double-click. (Because of the time problem, just a simple trial of this method (easy to use), has not changed the source code to view the picture, so it is not posted out)
---------------------------------
Speaking of this simple summary of the relevant delay operation:
00001. suggested methods to use
-(void) delay1{ //delay execution do not use sleep, disadvantage: stuck to the current thread [Nsthread sleepfortimeinterval:3]; NSLog (@ "operation");}
00002. Method Two
-(void) delay2{ //Once the delay task is customized, the master current thread will not be jammed [self performselector: @selector (Download:) withobject:@ "/HTTP/ Beautiful. jpg "Afterdelay:3";}
00003. Method Three
-(void) delay3{ //3 seconds back to the main thread to execute code in block dispatch_queue_t queue = Dispatch_get_main_queue (); Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (3 * nsec_per_sec)), queue, ^{ NSLog (@ "------ Task------%@ ", [Nsthread CurrentThread]); });
00004. Method Four
-(void) delay4{ //3 seconds after automatically opening a new thread to execute code in block dispatch_queue_t queue = Dispatch_get_global_queue (dispatch_queue_ Priority_default, 0); Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (3 * nsec_per_sec)), queue, ^{ NSLog (@ "------ Task------%@ ", [Nsthread CurrentThread]); });
About iOS delay operation, Periodic summary (part about click, double-click event Conflict)