iOS 14背景图片在应用程序重新加载之前不会更新



有人能告诉我为什么以下代码在第一次运行时或应用程序重新加载时能完美工作吗?然而,它并没有改变VC的背景图像,尽管我可以看到它逐步通过代码。当应用程序被刷走并重新加载时,图像确实正确加载。

我被难住了。任何想法都将不胜感激。

祝福,--标记

if CacheManager.getIsUserBackGround() {

//get a refrerence to the the documents for the app
let fileManager = FileManager.default
//get the path from Constants
let imagePath = Constants.getImage()


//check if not nil, and if not set the background pict
if imagePath != "" {
if fileManager.fileExists(atPath: imagePath!) {

DispatchQueue.main.async {
let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
backgroundImage.image = UIImage(contentsOfFile: imagePath!)!
backgroundImage.contentMode = UIView.ContentMode.scaleAspectFill
self.view.insertSubview(backgroundImage, at: 0)
}

}else{
DispatchQueue.main.async {
print("error")
//                        Alerts.showAlert(title: "Attention", message: "A user selected image from the Photos Library has not been saved. n n Tap the Gear icon on the 'Lists' screen and select the 'Set background from Photos' option to save an image.", vc: self)
}

}
}

我让事情变得更加困难!

我发现,每次更改图像时,我都会添加一个视图(以及内存开销(,当应用程序重置时,它只使用最后保存的图像。

简单的解决方案是忽略背景视图,添加UIImageView并将图像更改为该视图!生活和学习!

最新更新