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)")
            }
        }
    }
}
相关推荐
SomeOtherTime几秒前
第 1 讲:内存布局与所有权解剖——栈帧、胖指针与“移动/拷贝”在汇编层面的真实面目
java·开发语言·汇编
总要学点什么24 分钟前
第106篇:三维特效-流动线效果——让一颗光点沿整条线一路滚到头
开发语言·javascript·ecmascript·gis·webgl·材质·cesium
大可不必了11 小时前
03 函数定义和调用
开发语言·python
I_belong_to_jesus11 小时前
C++关于分支预测的优化1
开发语言·c++·算法
承渊政道12 小时前
【Python编程—从入门到实践】(记分与闯关:用Python+Pygame,打造越战越精彩的太空大战!)
开发语言·python·pycharm·游戏程序·pygame
爱学习的程序媛12 小时前
Python常用框架梳理
开发语言·后端·python·ai·web·后端框架·python框架
eggwyw14 小时前
Anaconda安装卸载的详细流程指南
开发语言·python
another heaven18 小时前
【C/C++ Ranges 是零开销抽象吗?拆开管道、惰性求值和编译期膨胀】
c语言·开发语言·c++
SomeOtherTime19 小时前
Rust 闭包语法和原理(AI回答)
开发语言·后端·rust
apcipot_rain20 小时前
C++转Java日记(10)
java·开发语言