其他分享
首页 > 其他分享> > iOS15的状态栏高度获取

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

标签:statusBarManager2,set,iOS15,状态栏,windowScene,windows,height,获取,size
来源: https://blog.csdn.net/weixin_52192405/article/details/122520813