Can#39;t change UIImageView image in function (SWIFT)(无法在函数中更改 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法在函数中更改 UIImageView 图像(SWIFT)
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
