About iOS delay operation, Periodic summary (part about click, double-click event Conflict)

Source: Internet
Author: User

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)

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.