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)")
            }
        }
    }
}
相关推荐
小白学大数据12 分钟前
Python 项目实战:用 Flask 构建生产级 MySQL 增删改查 REST API
开发语言·人工智能·python·mysql·flask
Nil20825 分钟前
leetcode 20有效的括号
开发语言
世纪末の魔术师27 分钟前
从 Healthory 到 Nature Aimanic:两款 iOS App 审核实战后,我总结了这份过审清单
ios·ios过审·苹果过审·ios应用过审
jaysee-sjc35 分钟前
【苍穹外卖】Day01:从零认识企业级项目开发
java·开发语言·数据库·mysql·spring·intellij-idea·mybatis
ThornArmor39 分钟前
《向内深潜,向外飞掠》
c语言·开发语言·c++·vim·visual studio
传奇开心果编程40 分钟前
【仓颉语言基础语法学与练】第1课:从零开始
开发语言·学习·华为
君顾144 分钟前
本地AI错题纠正小程序:端侧推理与错题闭环实战
java·开发语言·错题
庚鑫1 小时前
macOS 27 上维护 Xcode 15.2 老项目:一次 AssetCatalogSimulatorAgent 构建故障排查
ios·apple
吠品1 小时前
Python 写入 Excel 的两种主流方案实际用法总结
c语言·开发语言·算法