ios13 报错Assertion failure in -[_UINavigationBarContentView setLayoutMargins:]

在iOS 13上,不允许更改私有视图的布局边距。因此,扩展框架以消除布局边距可以作为替代解决方案。

swift语言解决方案

for view in subviews {
    if #available(iOS 13.0, *) {
        let margins = view.layoutMargins
        var frame = view.frame
        frame.origin.x = -margins.left
        frame.size.width += (margins.left + margins.right)
        view.frame = frame
    } else {
        view.layoutMargins = .zero
    }
}

oc语言解决方案:

if (@available(iOS 13.0, *)) {
    UIEdgeInsets margins = view.layoutMargins;
    CGRect frame = view.frame;
    frame.origin.x = -margins.left;
    frame.origin.y = -margins.top;
    frame.size.width += (margins.left + margins.right);
    frame.size.height += (margins.top + margins.bottom);
    view.frame = frame;
}else {
    view.layoutMargins = UIEdgeInsetsZero;
}

你可能感兴趣的:(ios13 报错Assertion failure in -[_UINavigationBarContentView setLayoutMargins:])