在Xcode 11中,我们无法使用Material来构建应用。
错误信息如下:
*** Assertion failure in -[_UINavigationBarContentView setLayoutMargins:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3899.13.13/_UINavigationBarContentView.m:703
在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;
}