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

Swift iOS 14背景图片在应用程序重新加载之前不会更新,swift,ios14,Swift,Ios14,有谁能告诉我,为什么下面的代码在第一次运行时,或者在应用程序重新加载时可以完美工作?不过,它不会改变VC的背景图像,尽管我可以看到它一步一步地完成代码。当刷走并重新加载应用程序时,图像确实正确加载 我被难住了。任何想法都将不胜感激 祝福,, --标记 我让事情变得更难了 我发现每次更改图像时,我都会添加一个视图(以及内存开销),当应用程序重置时,它只使用保存的最后一个图像 简单的解决方案是忽略背景视图,添加UIImageView并将图像更改为该视图!活到老学到老 if CacheManager.

有谁能告诉我,为什么下面的代码在第一次运行时,或者在应用程序重新加载时可以完美工作?不过,它不会改变VC的背景图像,尽管我可以看到它一步一步地完成代码。当刷走并重新加载应用程序时,图像确实正确加载

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

祝福,, --标记


我让事情变得更难了

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

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

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)
                        }
                        
                    }
                }