曾经的获取状态栏高度可以这样写:
[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