如何在 ios13 的状态栏上覆盖视图


fileprivate lazy var netTipWindow:UIWindow = {
let window = UIWindow(frame: CGRect(x: 0, y: topMargins, width: UIScreenW, height: realheight))
window.backgroundColor = .clear
window.windowLevel = .alert
window.isHidden = false
window.rootViewController = UIViewController()
window.rootViewController?.view.addSubview(self)
frame = CGRect(x: 0, y: -(topMargins + realheight), width: UIScreenW, height: realheight)
return window
}()

我的代码在ios 12中运行良好,但它的工作方式与图片相同。

另外,我尝试了此代码,没有区别

fileprivate lazy var netTipWindow:UIWindow = {
let window = UIWindow(frame: CGRect(x: 0, y: topMargins, width: UIScreenW, height: realheight))
window.backgroundColor = .clear
window.windowLevel = .alert
window.isHidden = false
if #available(iOS 13, *) {
window.addSubview(self)
} else {
window.rootViewController = UIViewController()
window.rootViewController?.view.addSubview(self)
}
frame = CGRect(x: 0, y: -(topMargins + realheight), width: UIScreenW, height: realheight)
return window
}()

iOS 13 状态栏

这段代码....

- (BOOL)prefersStatusBarHidden {
if (@available(iOS 13.0, *)) {
// safearea iPhone x, xr ..
if ([[[UIApplication sharedApplication] delegate] window].safeAreaInsets.top > 20.0) {
return NO;
}
else {
return YES;
}
}
else {
return NO;
}
}

最新更新