I am adding an overlay over the status bar of iphone. But when i switched over to IOS 13.1 on xcode 11.1, I am unable to present it over the status bar using UIWindow class
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
}
}
The same code if executed in Xcode 11.1 on IOS 13.1 then it gives this result in debugger ():-
Whereas, in xcode 10.2 on IOS 12.2 it gives me this result
End result in IOS 13.1, Xcode 11.1 is
And end result in IOS 12.2, xcode 10.2 is
How can i present overlay over statubar in IOS 13?
The relative APIs and values should have been deprecated in the documents.
The workaround we currrently have is to override prefersStatusBarHidden
.
Checkout the post I found here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.