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)")
            }
        }
    }
}
相关推荐
geovindu32 分钟前
python:Lasso
开发语言·后端·python·算法
多加点辣也没关系1 小时前
JavaScript|第42章:安全与最佳实践
开发语言·javascript·安全
3095566661 小时前
股票数据落库前的去重与主键设计:一次 SQLite 写入实录
java·开发语言·jvm·数据库·redis·python·sqlite
利威尔xu2 小时前
2026-11-19-Go反射为什么慢面试
开发语言·面试·golang
茶底世界之下2 小时前
海边书店的阴天:用 Awaking 留住青绿与暖灯
ios·app·产品
山楂树の2 小时前
Python 函数:参数、作用域、Lambda 与类型注解
开发语言·python
旖旎夜光2 小时前
【C 语言】(一)(下)指针进阶:const、二级指针、函数指针与指针题
c语言·开发语言·笔记·学习
炸薯条!3 小时前
Python装饰器详解:从闭包原理到语法糖,再到多个装饰器
开发语言·python
星落梦生3 小时前
苍穹外卖day3——阿里云oss文件上传
java·开发语言
Risehuxyc4 小时前
PHP函数注释怎么写
开发语言·php