我正在尝试为导航栏设置背景图片。
guard let navigationBar = navigationController?.navigationBar else { return }
let size = CGSize(width: navigationBar.bounds.width,
height: navigationBar.bounds.height + UIApplication.shared.statusBarFrame.height)
let image = #imageLiteral(resourceName: "NavigationBackground").resizedImage(newSize: size)
navigationBar.barTintColor = UIColor(patternImage: image)
func resizedImage(newSize: CGSize) -> UIImage {
// Guard newSize is different
guard self.size != newSize else { return self }
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
self.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}
但是当我这样做时,显示导航栏的动画在模拟器和真实设备上变得非常慢。我做错了什么?
添加信息:看起来与事实相关的问题是在开始屏幕上我隐藏了viewWillAppear中的导航栏,然后在viewWillDisappear中再次显示它。如果我在第一个屏幕上显示导航,从屏幕到屏幕的导航没有问题