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

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

问题描述

我已经在声明此函数后调用了该函数,并且一切正常,但是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
}

Apple参考

注意:
在大多数情况下,仅在应用程序的主线程中使用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.

致谢

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

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