时间:2021-07-15 09:28:18 | 栏目:iOS代码 | 点击:次
原全屏适配在iPhoneX会由于安全区域的变化导致显示不全。
解决方案如下:
在self.view上添加一个view,剩下的视图基于该view布局,view的约束随self.view.safeAreaInsets的改变需要重置:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor blackColor]; if (@available(iOS 11, *)) { [self setAdditionalSafeAreaInsets:self.view.safeAreaInsets]; } [self defaultUI]; [self addNotification]; } //iOS11新增,安全区域发生改变时调用 - (void)viewSafeAreaInsetsDidChange{ [super viewSafeAreaInsetsDidChange]; [self defaultUIWithSafeAreaInsets:self.view.safeAreaInsets]; }
总结