GCD Timer operation

Source: Internet
Author: User

var seconds = 10//countdown time Let queue = Dispatch_get_global_queue (dispatch_queue_priority_default, 0) Let timer        = Dispatch_source_create (dispatch_source_type_timer, 0, 0,queue); Dispatch_source_set_timer (timer,dispatch_walltime (nil, 0), 1 * nsec_per_sec, 0); Execute Dispatch_source_set_event_handler per second (timer) {if (seconds<=0) {//Countdown end, Close dispatch                _source_cancel (timer); Dispatch_async (Dispatch_get_main_queue (), {//SET interface button display according to your own needs set Btn.settitlecolor (U Icolor.blackcolor (), forstate:. Normal) Btn.settitle ("Get Verification Code", Forstate:.) Normal) Btn.titlelabel?.            Font = defaultFont14 btn.userinteractionenabled = true}); }else{Dispatch_async (Dispatch_get_main_queue (), {uiview.beginanimation         S (Nil, Context:nil) uiview.setanimationduration (1)       }) Dispatch_async (Dispatch_get_main_queue (), {//Settings interface button display According to your own needs set Uiview.beginanimations (Nil, Context:nil) uiview.setanimationduration (1) btn.s Ettitlecolor (Uicolor.orangecolor (), forstate:. Normal) Btn.settitle ("\ (seconds) seconds after Resend", Forstate:. Normal) Btn.titlelabel?. Font = uifont.systemfontofsize (one) uiview.commitanimations () Btn.userinteractionenab LED = false}) seconds-= 1}} dispatch_resume (Time R

10 second timer. Organize your Memo

GCD Timer operation

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.