UIScrollView 在滚动时暂停 NSTimer

UIScrollView pauses NSTimer while scrolling(UIScrollView 在滚动时暂停 NSTimer)
本文介绍了UIScrollView 在滚动时暂停 NSTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 UIScrollView,它有一系列快速更新数字的标签(每 0.06 秒).然而,当滚动视图移动时,NSTimer 会暂停,直到滚动和弹性动画完成后才会继续.

I have a UIScrollView that has a series of labels which are rapidly updating numbers (every .06 seconds). While the scroll view is moving, however, the NSTimer is paused and does not continue until after the scrolling and the elastic animation have finished.

如何避免这种情况并让 NSTimer 运行而不管滚动视图的状态如何?

How can I avoid this and have the NSTimer run regardless of the state of the scroll view?

推荐答案

解决此问题的简单方法是将 NSTimer 添加到 mainRunLoop.

An easy way to fix this is adding your NSTimer to the mainRunLoop.

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

要从所有安装了计时器的运行循环模式中删除计时器,请向计时器发送 invalidate 消息.

To remove a timer from all run loop modes on which it is installed, send an invalidate message to the timer.

这篇关于UIScrollView 在滚动时暂停 NSTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定义、交互式)视图控制器呈现和解除处理滚动视图)