ios11 劉海屏 安全區(qū)域 適配 彈框區(qū)域適配

網(wǎng)上看了很多 自己的代碼里面最終還是采用了自己的辦法

我采用安全區(qū)域做

首先在基類自定義了個vkview 如果非SB或者xib做的話 就可以用到

- (UIView*)vkView {

? ? if(!_vkView) {

? ? ? ? if(@available(iOS11.0, *)) {

? ? ? ? ? ? self.view.backgroundColor=VKHexColor(app_White_Color);

? ? ? ? ? ? _vkView= [[UIViewalloc]init];

? ? ? ? ? ? [self.viewaddSubview:_vkView];

? ? ? ? ? ? [_vkViewmas_makeConstraints:^(MASConstraintMaker*make) {

? ? ? ? ? ? ? ? make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop);

? ? ? ? ? ? ? ? make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);

? ? ? ? ? ? ? ? make.left.mas_equalTo(self.view.mas_safeAreaLayoutGuideLeft);

? ? ? ? ? ? ? ? make.right.mas_equalTo(self.view.mas_safeAreaLayoutGuideRight);

? ? ? ? ? ? }];

? ? ? ? }else{

? ? ? ? ? ? //適配狀態(tài)欄

? ? ? ? ? ? if (self.navigationController.navigationBarHidden || !self.navigationController) {

? ? ? ? ? ? ? ? self.view.backgroundColor=VKHexColor(app_White_Color);

? ? ? ? ? ? ? ? _vkView= [[UIViewalloc]init];

? ? ? ? ? ? ? ? [self.viewaddSubview:_vkView];

? ? ? ? ? ? ? ? [_vkViewmas_makeConstraints:^(MASConstraintMaker*make) {

? ? ? ? ? ? ? ? ? ? make.top.mas_equalTo(self.view).offset(20);

? ? ? ? ? ? ? ? ? ? make.bottom.left.right.mas_equalTo(self.view);

? ? ? ? ? ? ? ? }];

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? _vkView=self.view;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? _vkView.backgroundColor = VKHexColor(app_White_Color);

? ? }

? ? return _vkView;

}

用vkview的時候 記得在點語法之前 告知導航欄隱藏的情況

二 ,劉海屏有時候需要判斷

1》window.safeAreaLayoutGuide.layoutFrame.size.height? !=kScreenHeight ??kScreenHeight是宏屏高

2》[UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom > 0

三,有時候需要彈框 需要精確定位

self是封裝的彈框view

[[[UIApplication sharedApplication].keyWindow.subviews objectAtIndex:0] addSubview:self];

? ? if(@available(iOS11.0, *)) {

? ? ? ? [selfmas_makeConstraints:^(MASConstraintMaker*make) {

? ? ? ? ? ? make.top.mas_equalTo(_toPoint.y);

? ? ? ? ? ? make.left.mas_equalTo([[UIApplication sharedApplication].keyWindow.subviews objectAtIndex:0].mas_safeAreaLayoutGuideLeft);

? ? ? ? ? ? make.right.mas_equalTo([[UIApplication sharedApplication].keyWindow.subviews objectAtIndex:0].mas_safeAreaLayoutGuideRight);

? ? ? ? ? ? make.bottom.mas_equalTo([[UIApplication sharedApplication].keyWindow.subviews objectAtIndex:0].mas_safeAreaLayoutGuideBottom);

? ? ? ? }];

? ? }else{

? ? ? ? [selfmas_makeConstraints:^(MASConstraintMaker*make) {

? ? ? ? ? ? make.top.mas_equalTo(_toPoint.y);

? ? ? ? ? ? make.left.mas_equalTo([[UIApplication sharedApplication].keyWindow.subviews objectAtIndex:0].mas_left);

? ? ? ? ? ? make.right.mas_equalTo([[UIApplication sharedApplication].keyWindow.subviews objectAtIndex:0].mas_right);

? ? ? ? ? ? make.bottom.mas_equalTo([[UIApplication sharedApplication].keyWindow.subviews objectAtIndex:0].mas_bottom);

? ? ? ? }];

? ? }

其中topoint是

//獲取絕對高度

? ? ? ? ? ? UIWindow*window = [[[UIApplicationsharedApplication]delegate]window];

? ? ? ? ? ? CGRectrect = [weakSelf.segmentViewconvertRect:weakSelf.segmentView.boundstoView:window];

CGPointMake(0, rect.origin.y+rect.size.height) 獲取

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容