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)


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01