Can't change UIImageView image in function (SWIFT)

前端 未结 2 864
你的背包
你的背包 2021-01-29 14:43

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.

2条回答
  •  孤街浪徒
    2021-01-29 15:35

    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 Reference

    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.

    Regards

提交回复
热议问题