UI 返回导航堆栈中的上一个 ViewController 时冻结一秒钟
UI freezes for a second when returning to the previous ViewController in Navigation Stack
我无法弄清楚是什么导致 UI 在我按下后退按钮时冻结一秒钟。在我将背景图像添加到我正在转换的 viewController 后,它开始发生。如果我只使用“白色”作为我的背景颜色,过渡不会冻结,它只会在我添加图像后冻结。
这是它的样子的 gif 图...
https://gfycat.com/waryagileichidna
这是我在 viewDidLoad 中调用的用于设置背景图片的扩展...
extension UIView {
func addBackground(image:String) {
self.backgroundColor = .white
// screen width and height:
let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height
let imageViewBackground = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
imageViewBackground.image = UIImage(named: "\(image)")
imageViewBackground.alpha = 0.5
// you can change the content mode:
imageViewBackground.contentMode = UIView.ContentMode.scaleAspectFill
self.addSubview(imageViewBackground)
self.sendSubviewToBack(imageViewBackground)
}
}
您可以尝试将以下行添加到您在 viewDidLoad
中调用的 addBackground
方法中吗?
imageViewBackground.clipsToBounds = true
我觉得这应该可以解决问题。这看起来不像是冻结。
我无法弄清楚是什么导致 UI 在我按下后退按钮时冻结一秒钟。在我将背景图像添加到我正在转换的 viewController 后,它开始发生。如果我只使用“白色”作为我的背景颜色,过渡不会冻结,它只会在我添加图像后冻结。
这是它的样子的 gif 图...
https://gfycat.com/waryagileichidna
这是我在 viewDidLoad 中调用的用于设置背景图片的扩展...
extension UIView {
func addBackground(image:String) {
self.backgroundColor = .white
// screen width and height:
let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height
let imageViewBackground = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
imageViewBackground.image = UIImage(named: "\(image)")
imageViewBackground.alpha = 0.5
// you can change the content mode:
imageViewBackground.contentMode = UIView.ContentMode.scaleAspectFill
self.addSubview(imageViewBackground)
self.sendSubviewToBack(imageViewBackground)
}
}
您可以尝试将以下行添加到您在 viewDidLoad
中调用的 addBackground
方法中吗?
imageViewBackground.clipsToBounds = true
我觉得这应该可以解决问题。这看起来不像是冻结。