The simplest solution is to use a center position.
if blurView == nil {
let centerPos = self.window?.rootViewController?.view.center ?? .zero
blurView?.center = centerPos
self.window?.rootViewController?.view.addSubview(blurView!)
}
So the final code snippet based on the provided code is like the following.
override func applicationWillResignActive(_ application: UIApplication) {
if let view = self.window.rootViewController?.view.subviews.first(where: {$0.tag == TAG_BLUR_VIEW}){
view.removeFromSuperview()
blurView = nil
}
if blurView == nil{
blurView = UIImageView(image: UIImage(named: "splash.jpg"))
blurView?.backgroundColor = UIColor .white
blurView?.tag = TAG_BLUR_VIEW
let centerPos = self.window?.rootViewController?.view.center ?? .zero
blurView?.center = centerPos
}
self.window.rootViewController?.view.insertSubview(blurView!, at: 0)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…