【发布时间】:2020-02-25 15:11:58
【问题描述】:
我在 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 中执行相同的代码,那么它会在调试器 () 中给出这个结果:-
然而,在 IOS 12.2 上的 xcode 10.2 中,它给了我这个结果
IOS 13.1 的最终结果,Xcode 11.1 是
IOS 12.2 的最终结果是,xcode 10.2 是
如何在 IOS 13 中显示覆盖状态栏?
【问题讨论】:
标签: ios swift ios13 xcode11 uiwindow