gpt4 book ai didi

ios - 简单的 SwiftUI 代码产生 : UIViewAlertForUnsatisfiableConstraints. 为什么?

转载 作者:行者123 更新时间:2023-12-01 23:32:20 25 4
gpt4 key购买 nike

环境 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.

问题:这是一个错误吗?或者,如果没有,发生了什么并采取补救措施?

最佳答案

NavigationBarTitle 和 NavigationTitle 从 iOS 14.3 开始弃用。尝试在导航 View 上添加 .navigationViewStyle(StackNavigationViewStyle())

此解决方案的所有功劳都归功于 https://stackoverflow.com/a/66024249/15184473

关于ios - 简单的 SwiftUI 代码产生 : UIViewAlertForUnsatisfiableConstraints. 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66130482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com