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