我想在应用程序向用户显示其视图之前加载一组图像,自定义延迟例如 5 毫秒。有什么帮助吗??
我在 UIViewController 中使用了 UIImageView,这是我的代码:
import UIKit
class CustomViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var logoImage: [UIImage] = [
UIImage(named: "splash_logo_1.png")!,
UIImage(named: "splash_logo_2.png")!,
UIImage(named: "splash_logo_3.png")!,
UIImage(named: "splash_logo_4.png")!,
UIImage(named: "splash_logo_5.png")!,
UIImage(named: "splash_logo_6.png")!,
UIImage(named: "splash_logo_7.png")!,
UIImage(named: "splash_logo_8.png")!,
UIImage(named: "splash_logo_9.png")!,
]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8 , execute: {
// Put your code which should be executed with a delay here
for i in 1..<self.logoImage.count
{
let image = self.logoImage[i]
self.imageView.image = image
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
构建应用程序后,它只显示最后一张图片 (plash_logo_9.png)。
那么问题出在哪里..?