【发布时间】:2020-10-31 18:56:28
【问题描述】:
当我按下返回按钮时,我无法弄清楚是什么导致 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)
}
}
【问题讨论】:
-
这个方法的调用代码在哪里?
-
某些东西需要在主线程上。请添加更多代码。
-
尝试在主线程上添加过渡代码
-
尝试使用 Instruments 中的时间分析器来查看花费最多的时间。
标签: ios swift uiviewcontroller uinavigationcontroller