UIActivityIndicatorView 在加载完成后才显示
我在当前导航到视图控制器上有一个按钮,连接到 IBAction。
在 IBAction 中,我像往常一样使用 [self.view addSubView] 创建一个 UIActivityIndicatorView,然后加载一些图片。
我已经在指示器视图、视图控制器和窗口上尝试过 setNeedsDisplay,但它仍然在显示指示器之前加载图片,这对我来说当然毫无用处。
因此,我正在寻找一种方法来强制立即重绘(当我多想一点时,它不太可能起作用),或者一种在指示器出现后加载图片的方法,或者一种启动单独的线程或类似的开始动画/显示指示器,或者将指示器放在单独的视图控制器中,并以某种方式强制它在继续图片加载之前添加/显示自身。
建议?
I have a button on the currently navigated to viewcontroller, connected to an IBAction.
In the IBAction I create a UIActivityIndicatorView as usual, with [self.view addSubView], then load some pictures.
I've tried setNeedsDisplay on the indicator view, the view controller, and the window, but it still loads the pictures before showing the indicator, which of course is quite useless to me.
So I'm looking for a way to either force an instant redraw (which when I think a little more about it is unlikely to make work), or a way to load the pictures after the indicator has appeared, or a way to launch a separate thread or similar to start animating / show the indicator, or put the indicator in a separate viewcontroller and somehow force it to add/show itself before going on to the picture-loading.
Recommendations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,我所做的就是生成一个新线程,这会在后台加载内容时释放主线程来处理 UI 交互。
首先显示
UIActivityIndicatorView
,然后生成一个加载图像的新线程,然后在新线程中执行的方法的最后一行隐藏UIActivityIndicatorView
。这是一个示例:
在您的
loadImages
方法中:What I do in this situation is spawn a new thread, which frees up the main thread to handle UI interaction while stuff is loading in the background.
First show the
UIActivityIndicatorView
, then spawn a new thread that loads the images, then on the last line of the method that is executed in the new thread, hide theUIActivityIndicatorView
.Here's an example:
In your
loadImages
method: