美文网首页
iPhoneX的刘海屏安全距适配

iPhoneX的刘海屏安全距适配

作者: 文子飞_ | 来源:发表于2020-11-01 00:25 被阅读0次

刘海屏:顶部安全距离44、有导航栏(44)88,底部安全距离34、有tabbar(49)83

- (void)addConstraint
{
      self.multTableView.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview()
            make.bottom.equalTo(self.footerView.snp.top)
            if #available(iOS 11, *) {
                make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
            } else {
                make.top.equalToSuperview()
            }
        }
        self.footerView.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(55)
            if #available(iOS 11, *) {
                make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom)
            } else {
                make.top.equalToSuperview()
            }
        }
        
        // 填补self.view与footerView之间的空隙
        let safeAreaBottomSpaceView = UIView()
        safeAreaBottomSpaceView.backgroundColor = .cyan
        self.view.addSubview(safeAreaBottomSpaceView)
        safeAreaBottomSpaceView.snp.makeConstraints { (make) in
            make.leading.right.bottom.equalToSuperview()
            make.top.equalTo(self.footerView.snp.bottom)
        }
}

- (void)addConstraint
{
    [super addConstraint];

    [self.navigationBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(self.view);
        make.height.mas_equalTo(kTopHeight);
    }];
    
    CGFloat kFooterViewHeight = 65.0;
    [self.safeAreaBottomBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.footerView);
        make.bottom.mas_equalTo(self.view);
    }];
    [self.footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.height.mas_equalTo(kFooterViewHeight);
        if (@available(iOS 11.0, *)) {
            make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.mas_equalTo(self.mas_bottomLayoutGuideBottom);
            //make.bottom.mas_equalTo(self.view);
        }
    }];
}

相关文章

网友评论

      本文标题:iPhoneX的刘海屏安全距适配

      本文链接:https://www.haomeiwen.com/subject/vctyvktx.html