For more information about iOS latency operations, see the following section (for more information about Click and double-click event conflicts) and ios latency
I have previously written a simple image viewer. When I click an image and double-click an event, I encountered a problem and clicked the event operation in a delayed manner.
Method 1:
Details: 1. Set global variables
bool doubleTap;
Set the delay operation in the click event Method
Click the time delay:
Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (0.2 * NSEC_PER_SEC), dispatch_get_main_queue (), ^ {if (doubleTap = YES) return; // click operations related to the event });
* *** When double-clicking:
doubleTap = YES;
In this way, NO single-host event-related operations will be performed after 0.2 seconds. Double-click the operation and remember to set it (doubleTap = NO)
* *** When double-clicking an event:
Click an event 0.2 seconds later
-------------------------------------
Method 2: (during the Netease interview, I talked about this issue. I spoke about my methods. Daniel gave me two methods-I can only say that Daniel is Daniel)
[self performSelector:@selector(test) withObject:nil afterDelay:.2]; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(test) object:nil];
The above two methods are simply to say, one is to perform a delay operation, the other is to cancel the delay operation, and then double-click the single machine through this operation. (Due to time issues, I just tried this method (easy to use) and didn't modify the source code of the image, so I won't post it)
---------------------------------
In this simple summary, the related latency operations are as follows:
00001. Recommended Methods
-(Void) delay1 {// do not use sleep for delayed execution. Disadvantages: getting stuck in the current thread [NSThread sleepForTimeInterval: 3]; NSLog (@ "operation ");}
00002. method 2
-(Void) delay2 {// once a delayed task is customized, the current thread [self defined mselector: @ selector (download :) withObject: @ "http: // .jpg" afterDelay: 3];}
00003. Method 3
-(Void) delay3 {// return to the Code dispatch_queue_t queue = queue (); dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) in the main thread execution block after 3 seconds) (3 * NSEC_PER_SEC), queue, ^ {NSLog (@ "------ task ------ % @", [NSThread currentThread]);}
00004. Method 4
-(Void) delay4 {// After 3 seconds, the Code dispatch_queue_t queue = queue (queue, 0); dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) in the new thread execution block is automatically Enabled) (3 * NSEC_PER_SEC), queue, ^ {NSLog (@ "------ task ------ % @", [NSThread currentThread]);}