Tips for using timers in IOS

Source: Internet
Author: User

1. Nstimer

With Nstimer on, if you drag the ScrollView will cause the timer to pause, and the lock screen must pause the timer, otherwise throw an exception.

Pause Timer Method [_stimer setfiredate:[nsdate distantfuture]];

Recovery Timer Method [_stimer setfiredate:[nsdate distantpast];

_stimer = [Nstimer scheduledtimerwithtimeinterval:interval                                                         target:timertarget                                                       selector: @selector ( Firetimer)                                                       userinfo:userinfo                                                        repeats:repeats];
[[Nsrunloop Mainrunloop] Addtimer:_stimer formode:nsrunloopcommonmodes];

2. Using the timer on GCD, if you drag the ScrollView, it will not affect the execution of the timer. However, on the lower version of ipad Mini, Apple does not optimize it, and the timer that is turned on in this way blocks the UI's response events.

            //turn on sub-line loads load musicuint64_t interval = Persecondtime *nsec_per_sec; dispatch_queue_t Queue= Dispatch_queue_create ("Timerqueue",0); _timers= Dispatch_source_create (Dispatch_source_type_timer,0,0, queue); Dispatch_source_set_timer (_timers, Dispatch_time (Dispatch_time_now,0), Interval,0);            mlweakself; Dispatch_source_set_event_handler (_timers,^()                                              {    //NSLog (@ "Timer%@", [Nsthread CurrentThread]);[Weakself Firetimer];            }); Dispatch_resume (_timers);

Tips for using timers in IOS

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.