iPhone UIActivityIndicatorView 未启动或停止
当我在 UIActivityIndicatorView 上调用 startAnimating 时,它不会启动。这是为什么呢?
[这是一个博客式的自我回答问题。下面的解决方案对我有用,但是,也许还有其他更好的解决方案?]
When I call startAnimating on a UIActivityIndicatorView, it doesn't start. Why is this?
[This is a blog-style self-answered question. The solution below works for me, but, maybe there are others that are better?]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您编写这样的代码:
您不会给 UI 时间来实际启动和停止活动指示器,因为所有计算都在主线程上。一种解决方案是在单独的线程中调用 startAnimating:
或者,您可以将计算放在单独的线程上,并在调用 stopAnimation 之前等待其完成。
If you write code like this:
You aren't giving the UI time to actually start and stop the activity indicator, because all of your computation is on the main thread. One solution is to call startAnimating in a separate thread:
Or, you could put your computation on a separate thread, and wait for it to finish before calling stopAnimation.
我通常这样做:
I usually do:
这个问题很有用。但答案中缺少的一件事是,每一件需要很长时间的事情都需要在单独的线程中执行,而不是在 UIActivityIndicatorView 中执行。这样它就不会停止响应 UI 界面。
This question is quite useful. But one thing that is missing in the answer post is , every thing that takes long time need to be perform in separate thread not the UIActivityIndicatorView. This way it won't stop responding to UI interface.
所有 UI 元素都需要位于主线程上
:
All UI elements require to be on main thread
then:
如果需要,可以使用 swift 3 版本:
If needed, swift 3 version:
好吧,抱歉,我的代码似乎是盲目的。
我已经这样结束了指示器:
因此,在一次运行之后,activityIndicator 已被完全删除。
Ok, sorry seems like I went through my code being blind.
I've ended the Indicator like this:
So after one run, the activityIndicator has been removed completely.