针对状态栏高度做一些操作
swift
import UIKit
class ViewController: UIViewController {
private var statusBarFrameObservation: NSKeyValueObservation?
override func viewDidLoad() {
super.viewDidLoad()
if let statusBarManager = UIApplication.shared.windows.first?.windowScene?.statusBarManager {
statusBarFrameObservation = statusBarManager.observe(\.statusBarFrame, options: [.new, .old]) { _, change in
// 处理状态栏变化
print("Status bar frame changed from \(change.oldValue) to \(change.newValue)")
}
}
}
}