ios multithreading animation uiscrollview

ios - El evento UIScrollView scroll bloquea la animación de UIView



multithreading animation (1)

Tengo un conjunto de animaciones de UIImageView que representan un valor actual y continuamente siguen subiendo ... idealmente, nunca parando, también en la vista hay un scrollView o y cada vez que estoy desplazando o acercando el scrollView, la animación se detiene, y se inicia nuevamente cuando scrollView deja de moverse por completo. Creo que esto se debe a un problema de enhebrado ya que todos los elementos de redibujado suceden en el hilo principal. Al principio probé la animación de UIView y luego incluso la animación central sin ningún efecto ... ¿Hay alguna forma de tener mi pastel y comérselo también?

Cualquier y toda ayuda sería apreciada

el código sigue

- (void)TestJackpotAtRate:(double)rateOfchange { double roc = rateOfchange; for (int i = 0; i < [_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) { }]; }


Como señaló danypata en mis comentarios a través de este hilo, mis elementos de IU personalizados no se actualizan mientras se desplaza UIScrollView. Tiene algo que ver con el hilo NStimer en lugar del hilo de animación, o posiblemente ambos si alguien puede aclarar. En cualquier caso, al desplazarse parece que todos los eventos de desplazamiento obtienen un uso exclusivo del bucle principal, la solución es poner el temporizador que está utilizando para hacer su animación en el mismo modo de bucle que es UITrackingLoopMode para que también use el bucle principal cuando desplazamiento y ...

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:foreveryNseconds target:self selector:@selector(AscendDigit:) userInfo:dict repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

Tada.