ios - UIScrollView scroll event blocks UIView animation -


i have animating set of uiimageview's represent current value , continually keeps ticking upwards...ideally never stopping, in view scrollview or , whenever i'm scrolling or zooming in scrollview, animation stops, , starts again when scrollview stops moving completely. believe due threading issue since redrawing elements happens on main thread, @ first tried uiview animation , core animation no effect...is there way have cake , eat too?

any , appreciated

code follows

- (void)testjackpotatrate:(double)rateofchange {     double roc = rateofchange;      (int = 0; < [_jackpotdigits count]; ++i)     {         roc = rateofchange/(pow(10, i));          uiimageview *jackpotdigit = [_jackpotdigits objectatindex:i];          float foreverynseconds = 1/roc;          nsdictionary *dict = @{@"interval"      :   [nsnumber numberwithfloat:foreverynseconds],                            @"jackpotdigit"  :   jackpotdigit                            };          [nstimer scheduledtimerwithtimeinterval:foreverynseconds target:self selector:@selector(ascenddigit:) userinfo:dict repeats:yes];     } }  -(void)ascenddigit:(nstimer*)timer {     nsdictionary *dict = [timer userinfo];      nstimeinterval interval = [(nsnumber*)[dict objectforkey:@"interval"] floatvalue];     uiimageview *jackpotdigit = [dict objectforkey:@"jackpotdigit"];      float duration = (interval < 1) ? interval : 1;      if (jackpotdigit.frame.origin.y < -230 )     {         nslog(@"hit");         [timer invalidate];         cgrect frame = jackpotdigit.frame;         frame.origin.y = 0;         [jackpotdigit setframe:frame];          [nstimer scheduledtimerwithtimeinterval:interval target:self selector:@selector(ascenddigit:) userinfo:dict repeats:yes];     }      [uiview animatewithduration:duration delay:0 options:uiviewanimationoptionallowuserinteraction animations:^      {          cgrect frame = [jackpotdigit frame];           double ydisplacement = 25;           frame.origin.y -= ydisplacement;           [jackpotdigit setframe:frame];       }                       completion:^(bool finished)      {       }];  } 

as danypata pointed out in comments via thread my custom ui elements not being updated while uiscrollview scrolled has nstimer thread rather animation thread, or possibly both if can clarify. in case when scrolling seems scroll events exclusive use of main loop, solution put timer using animation same loop mode uitrackingloopmode get's use of main loop when scrolling and...

nstimer *timer = [nstimer scheduledtimerwithtimeinterval:foreverynseconds target:self selector:@selector(ascenddigit:) userinfo:dict repeats:yes];  [[nsrunloop currentrunloop] addtimer:timer formode:nsrunloopcommonmodes]; 

tada.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -