iOS15的状态栏高度获取

曾经的获取状态栏高度可以这样写:

[UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager.statusBarFrame.size.height;

但是,iOS15更新了之后,就报警告了:

'windows' is deprecated: first deprecated in iOS 15.0 - Use UIWindowScene.windows on a relevant window scene instead

还可以用,就是会报警告。改成下面这样就好啦:

NSSet *set = [[UIApplication sharedApplication] connectedScenes];
UIWindowScene *windowScene = [set anyObject];
UIStatusBarManager *statusBarManager2 =  windowScene.statusBarManager;
NSLog(@"statusBarHeight %f", statusBarManager2.statusBarFrame.size.height);

iPhone12pm测试:

statusBarHeight 47.000000
上一篇:IOS15 Swift5 实现录音App


下一篇:ios15音频工具类封装