ios - performSelectorAfterDelay unreliable on Apple Watch -


i have stopwatch class updates view periodically in tick method. method gets triggered via

[self performselector:@selector(tick) withobject:self afterdelay:0.1f]; 

this works fine on iphone view gets updated approx. every tenth of second.

now want use same class achieve on apple watch. when start stopwatch view gets updated kind of ok. after 2 seconds framerate drops , stopwatch becomes unusable.

here whole tick method:

- (void)tick { if (!self.running) return; nstimeinterval currenttime = [nsdate timeintervalsincereferencedate]; nstimeinterval elapsed = currenttime - starttime; if (countdown) {     curtime = originaltime - (elapsed * 1000); }else {     curtime = originaltime + (elapsed * 1000);     curtime -= offset; }  [self.delegate stopwatch:self tick:curtime]; long thisthousand = curtime / 1000;  if (curtime > 0 || !countdown) {     if (thisthousand != lastthousand) {         long seconds = curtime / 1000;         if (countdown) seconds++;         [self.delegate stopwatch:self fullsecond:seconds];     }     lastthousand = curtime / 1000;     [self performselector:@selector(tick) withobject:self afterdelay:0.1f]; } else {     curtime = 0;     [self.delegate stopwatch:self fullsecond:0];     [self.delegate stopwatchstoped:self];     [self stoptimer]; } } 

any ideas on how work. or alternative solution?

many thanks!

edit: ui simple label , not fancy animation. label should set 0:00:00.1 0:00:00.2 , on.

if you're updating views method (i'm assuming [self.delegate stopwatch:self fullsecond:seconds] updates view?) if yes ought @ coreanimation. animations better designed handle view changes on time (after that's animation is!). if you're animating second hand create animation makes "tick" , repeat process indefinitely. there delegate methods inform when animation has completed can use other calculations.

look here docs on coreanimation.

an alternative performselector:afterdelay: use nstimer:

// timer ivar timer = [nstimer scheduledtimerwithtimeinterval:0.1 target:self selector:@selector(tick) userinfo:nil repeats:yes];  // stop timer [timer invalidate]; 

i suggest coreanimation first.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -