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)")
            }
        }
    }
}
相关推荐
传奇开心果编程1 天前
【Rust入门练中学】 第3课:数据类型
开发语言·学习·rust
泡泡鱼(敲代码中)1 天前
MySQL 学习笔记:DCL、函数与约束 —— 安全、效率、完整性的三板斧
开发语言·笔记·sql·学习·mysql·gitee
Tairitsu_H1 天前
[C++] 拷贝构造还是赋值重载?类默认成员函数细节详解
开发语言·c++·类和对象
goodlook01231 天前
opencode调用本地模型一(1.18.30版本安装)
开发语言
菜鸟~noob2331 天前
【电子战】第14篇:TOA 定位——圆交汇与到达时间【含matlab代码】
开发语言·matlab
HouWan1 天前
Flutter: MediaQuery.of(context) 为什么可能拖慢页面?
android·flutter·ios
SoaringHeart1 天前
Swift 进阶&封装:仿 Get 给SwiftUI 添加路由导航能力
swiftui·swift
itmigrate1 天前
Redis 开发高频隐形踩坑记录
开发语言·java-ee
白远山1 天前
本地游戏代练源码开发实战:架构设计与核心功能实现指南
java·开发语言·架构·需求分析
用户38034165882971 天前
Broadcast Extension 里的 Live Activity:一次跨进程妥协
ios·音视频开发