For more information about iOS latency operations, see the following section (for more information about Click and double-click event conflicts) and ios latency

Source: Internet
Author: User

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]);}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.