本文介绍了UIScrollView滚动事件阻止UIView动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一组UIImageView的动画集代表当前值并且不断向上滴答...理想情况下永远不会停止,在视图中也是一个scrollView或者当我滚动或放大scrollView时,动画停止,并在scrollView完全停止移动时再次启动。我相信这是由于一个线程问题,因为重绘元素都发生在主线程上,起初我尝试了UIView动画,然后甚至核心动画都没有效果......有没有办法让我的蛋糕也吃掉它?I have an animating set of UIImageView's that represent a current value and continually keeps ticking upwards...ideally never stopping, also in the view is a scrollView or to and whenever I'm scrolling or zooming in the scrollView, the animation stops, and starts up again when the scrollView stops moving completely. I believe this is due to a threading issue since redrawing elements all happens on the main thread, At first i tried UIView animation and then even core animation to no effect...Is there a way to have my cake and eat it too?任何和所有帮助将不胜感激Any and all help would be appreciated代码如下- (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) { }];}推荐答案 As danypata 在我的评论中通过这个帖子指出滚动UIScrollView时,我的自定义UI元素未更新它与NStimer线程而不是动画线程有关,或者如果有人可以澄清那么两者都有。在任何情况下,当滚动它似乎所有滚动事件都获得主循环的独占使用时,解决方案是将您用于执行动画的计时器放入相同的循环模式,即 UITrackingLoopMode 因此它也得到了使用滚动时的主循环和...As danypata pointed out in my comments via this thread My custom UI elements are not being updated while UIScrollView is scrolled It has something to do with the NStimer thread rather than the animation thread, or possibly both if someone can clarify. In any case when scrolling it seems all scroll events get exclusive use of the main loop, the solution is to put the timer you are using to do your animation into the same loop mode which is UITrackingLoopMode so it too get's use of the 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。 这篇关于UIScrollView滚动事件阻止UIView动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-04 12:44