- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在开发一个 iOS 应用程序,在 iOS 13 之前,它能够在弹出窗口出现时使状态栏“变暗”。这只需添加一个带有边界的 View 作为状态栏并应用即可完成0.5 alpha:
lazy var fadeStatusBar: UIView = {
let fadeStatusBar = UIView(frame: UIApplication.shared.statusBarView?.frame ?? UIApplication.shared.statusBarFrame)
fadeStatusBar.backgroundColor = UIColor.black
fadeStatusBar.alpha = 0
fadeStatusBar.translatesAutoresizingMaskIntoConstraints = false
return fadeStatusBar
}()
其中 statusBarView
是 UIApplication 的扩展:
extension UIApplication {
var statusBarView: UIView? {
if #available(iOS 13.0, *) {
let tag = 38482458385
if let statusBar = self.keyWindow?.viewWithTag(tag) {
return statusBar
} else {
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
statusBarView.tag = tag
self.keyWindow?.addSubview(statusBarView)
return statusBarView
}
} else {
if responds(to: Selector(("statusBar"))) {
return value(forKey: "statusBar") as? UIView
}
}
return nil
}
}
然后我可以将 fadeStatusBar alpha 属性设置为 0.5。然而,这在 iOS 13 中不再起作用。我只是想知道它是否仍然可以完成,因为我读到 another thread native iOS 应用程序也删除了此功能:
The status bar is rendered by a system process (out of the app process) on iOS 13 so there is no way for an app to change this. (Source: speaking to UIKit engineers at the WWDC 2019 labs.)
You can see this in the Apple Books app, which used to dim the status bar in its dark mode on iOS 12, but this does not happen on iOS 13.
不过,我的问题与上面提到的问题不同,因为问题是编辑状态栏本身的 alpha,而我很乐意使用覆盖 View 。任何能达到预期结果的建议将不胜感激。
最佳答案
您可以添加 View 并使其变暗,然后将其作为 subview 添加到状态栏,如下所示:
// Dim status bar
let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
let wFrame = window?.windowScene?.statusBarManager?.statusBarFrame
let statusBarView = UIView(frame: wFrame!)
statusBarView.restorationIdentifier = "statusBarView"
statusBarView.backgroundColor = UIColor.black.withAlphaComponent(0.6)
window?.addSubview(statusBarView)
如果您想将其恢复回来,您可以执行以下操作:
// Revert status bar back to normal
let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
for subview in window!.subviews {
if subview.restorationIdentifier == "statusBarView" {
subview.removeFromSuperview()
}
}
关于ios - 如何在 iOS 13 中调暗状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58074865/
我的代码遇到了很大的困难。我正在开发一个显示歌词和和弦的应用程序。我使用两个重叠的textview分隔了和弦和歌词。 我在这个项目中遇到的问题是音高改变功能。我尽我所能向我解释得更好: 和弦总数为12
我有一个游戏并使用 Tune 作为分析库。使用最新的 Unity (5.3.4f1) 并通过 Unity 获取 apk(无 eclipse/android studio)。 我的游戏在 Play 商店
我是一名优秀的程序员,十分优秀!