适用于iPhone X安全区域的ConstraintsWithVisualFormat

时间:2018-07-23 14:01:22

标签: objective-c iphone-x safearealayoutguide carbonkit

此行代码将转换为iPhone X的安全区域

    self.view.translatesAutoresizingMaskIntoConstraints = NO;
id views = @{
    @"carbonTabSwipe" : self.view,
    @"topLayoutGuide" : rootViewController.topLayoutGuide,
    @"bottomLayoutGuide" : rootViewController.bottomLayoutGuide
};

NSString *verticalFormat = @"V:[topLayoutGuide][carbonTabSwipe][bottomLayoutGuide]";
[rootViewController.view
    addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:verticalFormat
                                                           options:0
                                                           metrics:nil
                                                             views:views]];
[rootViewController.view
    addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[carbonTabSwipe]|"
                                                           options:0
                                                           metrics:nil
                                                             views:views]];

这适用于其他设备,但iPhone X的底部显示空格。

0 个答案:

没有答案