且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UIScrollView滚动事件阻止UIView动画

更新时间:2023-11-04 17:02:10

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。