iOS 安全区域适配

    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGFloat rectStatusHeight = rectStatus.size.height;
    NSLog(@"status width - %f", rectStatus.size.width); // 宽度
    NSLog(@"status height - %f", rectStatus.size.height);  // 高度
    [rootView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.top.equalTo(@(rectStatusHeight));
            make.left.right.bottom.equalTo(0);
        }
    }];

 

posted on 2019-01-28 11:03  sunyaxue  阅读(370)  评论(0编辑  收藏  举报

导航