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)")
            }
        }
    }
}
相关推荐
不吃香菜学java7 小时前
Redis的java客户端
java·开发语言·spring boot·redis·缓存
贵沫末8 小时前
python——打包自己的库并安装
开发语言·windows·python
文祐8 小时前
C++类之虚函数表及其内存布局(一个子类继承一个父类)
开发语言·c++
zuowei28898 小时前
华为网络设备配置文件备份与恢复(上传、下载、导出,导入)
开发语言·华为·php
xiaohe079 小时前
超详细 Python 爬虫指南
开发语言·爬虫·python
嗑嗑嗑瓜子的猫9 小时前
Java!它值得!
java·开发语言
xiaoshuaishuai89 小时前
C# GPU算力与管理
开发语言·windows·c#
lsx2024069 小时前
SVN 创建版本库
开发语言
xiaotao1319 小时前
01-编程基础与数学基石:Python错误与异常处理
开发语言·人工智能·python
皮卡蛋炒饭.10 小时前
线程的概念和控制
java·开发语言·jvm