iOS 13获取状态栏高度及iOS 11 适配不同机型
2020-12-01 本文已影响0人
桐丘
iOS 13 弃用了 UIApplication 对象的 statusBarFrame属性
iOS 13 获取状态栏高度
CGFloat statusHeight = appDelegate.window.windowScene.statusBarManager.statusBarFrame.size.height;
NSLog(@"状态栏:%lf", statusHeight);

iOS 11适配
仅针对非分屏模式。
获取window 的安全区域,此 window 指的是应用程序的主窗口,即 AppDelegate 对象中的属性 window。设为 insets, 最底层子视图硬编码形式布局如下:
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
UIEdgeInsets insets = appDelegate.window.safeAreaInsets;
NSLog(@"安全区域:%lf, %lf, %lf, %lf", insets.top, insets.left, insets.bottom, insets.right);
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, insets.top, self.view.frame.size.width - 20 * 2, self.view.frame.size.height - insets.top - insets.bottom)];
[self.view addSubview:view];
view.backgroundColor = [UIColor redColor];




