无法在函数中更改 UIImageView 图像(SWIFT) [英] Can't change UIImageView image in function (SWIFT)

查看:18
本文介绍了无法在函数中更改 UIImageView 图像(SWIFT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在声明后调用了这个函数,一切正常,但 UIImageViews 不会改变它们的图像.非常感谢您的帮助.

I have called this function after it is declared and everything works but the UIImageViews don't change their image. I would be very grateful for your help.

推荐答案

我认为是sleep(3)的问题,这行阻塞了主线程.而不是那种用途:

I think that the problem is the sleep(3), this line block the main thread. Instead of that use:

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
    // your code here
}

苹果参考

注意:
在大多数情况下,只在应用程序的主线程中使用 UIKit 类.对于从 UIResponder 派生的类或涉及以任何方式操纵应用的用户界面的类尤其如此.

Note:
For the most part, use UIKit classes only from your app’s main thread. This is particularly true for classes derived from UIResponder or that involve manipulating your app’s user interface in any way.

问候

这篇关于无法在函数中更改 UIImageView 图像(SWIFT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆