【发布时间】:2021-02-10 03:23:24
【问题描述】:
环境: Xcode 版本 12.4 (12D4e)
场景:我发现了一个明显违反约束的区域。
我将其缩小到 .navigationTitle。
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Text("Hello World")
}.navigationTitle("Turkey")
}
}
}
就是这样。
如果我删除 .navigationTitle(),它就会清除。
以下是控制台中列出的约束违规:
2021-02-09 19:14:38.578190-0800 NavBarCheck[6300:437683] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x600003149ef0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x12c01a770]-(6)-[_UIModernBarButton:0x12c0191e0'Turkey'] (active)>",
"<NSLayoutConstraint:0x600003149f40 'CB_Trailing_Trailing' _UIModernBarButton:0x12c0191e0'Turkey'.trailing <= _UIButtonBarButton:0x12c018560.trailing (active)>",
"<NSLayoutConstraint:0x60000314acb0 'UINav_static_button_horiz_position' _UIModernBarButton:0x12c01a770.leading == UILayoutGuide:0x600002b65260'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x60000314ad00 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x12c018560]-(0)-[UILayoutGuide:0x600002b65180'UINavigationBarItemContentLayoutGuide'] (active)>",
"<NSLayoutConstraint:0x60000314c780 'UINavItemContentGuide-trailing' UILayoutGuide:0x600002b65180'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x12ae0f100.trailing (active)>",
"<NSLayoutConstraint:0x60000314b3e0 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x12ae0f100.width == 0 (active)>",
"<NSLayoutConstraint:0x60000314cb40 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x600002b65260'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarContentView:0x12ae0f100 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600003149ef0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x12c01a770]-(6)-[_UIModernBarButton:0x12c0191e0'Turkey'] (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
问题:这是一个错误吗?或者如果不是,发生了什么并采取补救措施?
【问题讨论】:
-
如果你搜索“SwiftUI 约束”,这里有很多关于这个的问题。普遍的共识似乎是不关心它