iOS 13无法在iPhone的状态栏上显示级别为.statusbar的UIWindow

时间:2019-10-30 10:31:33

标签: ios swift ios13 xcode11 uiwindow

我正在iphone的状态栏上添加一个覆盖图。但是,当我在xcode 11.1上切换到IOS 13.1时,无法使用UIWindow类

在状态栏上显示它
class PassTroughWindow: UIWindow {
    var passTroughTag: Int?

    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {

        let hitView = super.hitTest(point, with: event)

        if let passTroughTag = passTroughTag {
            if passTroughTag == hitView?.tag {
                return nil
            }
        }
        return hitView
    }
}


    class ViewController: UIViewController {
                        var window: PassTroughWindow?
             @IBAction func alertButtonPressed(_ sender: UIButton) {
                        print("Height : \(UIApplication.shared.statusBarFrame.height)")
                        print("Height : \(UIApplication.shared.statusBarFrame.maxY)")
                        let frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: UIApplication.shared.statusBarFrame.maxY)
                        let banner = UIView(frame: frame)
                        banner.layer.cornerRadius = 2.5
                        banner.backgroundColor = UIColor.init(red: 128.0/255.0, green: 161.0/255.0, blue: 193.0/255.0, alpha: 1.0)

                        let label = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: frame.width, height: frame.height))
                        label.textAlignment = .center
                        label.font = .boldSystemFont(ofSize: 10)
                        label.text = "No internet connection"
                        label.textColor = .black
                        banner.addSubview(label)

                        self.window = PassTroughWindow(frame: UIScreen.main.bounds)
                        self.window?.rootViewController = UIViewController()
                        self.window?.windowLevel = .statusBar + 1
                        self.window?.addSubview(banner)
                        self.window?.makeKeyAndVisible()
                        self.window?.alpha = 1.0

                    }

        }

如果在IOS 13.1的Xcode 11.1中执行相同的代码,则在调试器()中给出此结果:- enter image description here

在IOS 12.2的xcode 10.2中,它给了我这个结果

enter image description here

IOS 13.1中的最终结果是Xcode 11.1

enter image description here

IOS 12.2和xcode 10.2中的最终结果是

enter image description here

如何在IOS 13中的状态栏上显示叠加图?

1 个答案:

答案 0 :(得分:0)

相关API和值应在文档中已弃用。

目前的解决方法是覆盖Buster

查看我发现的帖子here