swift 监听状态栏frame变化

针对状态栏高度做一些操作

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)")
            }
        }
    }
}
相关推荐
apcipot_rain2 小时前
C++转Java日记(06)
java·开发语言
SomeOtherTime9 小时前
Rust所有权(AI回答)
开发语言·后端·rust
Easyhood9 小时前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
白杨尚青10 小时前
C++进阶篇(六):map 和 set 的模拟实现——用红黑树封装 mymap/myset(迭代器 + operator[])
开发语言·c++·迭代器·stl·set·map·红黑树
kango12 小时前
iOS 远程推送全链路拆解:从 deviceToken 到多账号绑定
ios·app
饮水桶_T14 小时前
JAVA IO流笔记
开发语言·数据结构·算法
Felven16 小时前
C. Brr Brrr Patapim
c语言·开发语言
路溪非溪17 小时前
python标准库使用总结
开发语言·python
SomeOtherTime19 小时前
Rust 面向对象介绍(AI回答)
开发语言·python·rust
zh_xuan19 小时前
kotlin常见面试题
开发语言·kotlin·面试题