ios11 刘海屏 安全区域 适配 弹框区域适配

网上看了很多 自己的代码里面最终还是采用了自己的办法

我采用安全区域做

首先在基类自定义了个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{

            //适配状态栏

            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) 获取

你可能感兴趣的:(ios11 刘海屏 安全区域 适配 弹框区域适配)