SwiftUI无法同时满足约束
我已经做了6年以上的android开发者,但最近我开始做iOS。我拿起了SwiftUI,我觉得它很神奇,我制作了一些屏幕 然而,当我第一次点击文本字段时,我在日志中发现了这个错误。当我这样做时,屏幕将返回到上一个屏幕(我将从SwiftUI无法同时满足约束,swiftui,Swiftui,我已经做了6年以上的android开发者,但最近我开始做iOS。我拿起了SwiftUI,我觉得它很神奇,我制作了一些屏幕 然而,当我第一次点击文本字段时,我在日志中发现了这个错误。当我这样做时,屏幕将返回到上一个屏幕(我将从导航链接进入此屏幕) 我遇到的错误是: 2021-01-10 12:52:58.682264+0200 appName[2025:1085202] [LayoutConstraints] Unable to simultaneously satisfy constraints
导航链接
进入此屏幕)
我遇到的错误是:
2021-01-10 12:52:58.682264+0200 appName[2025:1085202] [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:0x280e898b0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x11d57ed20]-(6)-[_UIModernBarButton:0x11d57e3e0'Add Point'] (active)>",
"<NSLayoutConstraint:0x280e89900 'CB_Trailing_Trailing' _UIModernBarButton:0x11d57e3e0'Add Point'.trailing <= _UIButtonBarButton:0x11d57e010.trailing (active)>",
"<NSLayoutConstraint:0x280e8a440 'UINav_static_button_horiz_position' _UIModernBarButton:0x11d57ed20.leading == UILayoutGuide:0x28143ed80'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x280e8a490 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x11d57e010]-(0)-[UILayoutGuide:0x28143eca0'UINavigationBarItemContentLayoutGuide'] (active)>",
"<NSLayoutConstraint:0x280e436b0 'UINavItemContentGuide-trailing' UILayoutGuide:0x28143eca0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x11d543390.trailing (active)>",
"<NSLayoutConstraint:0x280e8ab70 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x11d543390.width == 0 (active)>",
"<NSLayoutConstraint:0x280e43d40 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x28143ed80'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarContentView:0x11d543390 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280e898b0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x11d57ed20]-(6)-[_UIModernBarButton:0x11d57e3e0'Add Point'] (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.
我删除了一些变量,这样代码就不那么容易理解了
我发现调试日志非常困难,如果有人能给我一些提示的话,我认为apple开发者文档非常模糊,很难理解。谢谢 我自己也遇到了这个问题。它必须是一个SwiftUI错误,因为一个只有文本字段的全新项目会触发错误。然而,这只发生在我的iPad上。但似乎是无害的。看起来和这些问题一样:---
import SwiftUI
struct AddEvent: View {
var body: some View {
NavigationView {
VStack {
TextField("Title", text: $title)
.font(Font.system(size: 16, weight: .bold, design: .serif))
.padding(10)
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color("AccentColor"), lineWidth: 1))
TextEditor(text: $details)
.font(Font.system(size: 15, weight: .bold, design: .serif))
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color("AccentColor"), lineWidth: 1))
.frame(maxWidth: .infinity, minHeight: 100, maxHeight: 150, alignment: .top)
DatePicker("Date and time", selection: $dateTime)
.padding()
Button(action: {
self.showingDetail.toggle()
}) {
Text("Pick coordonates")
}.sheet(isPresented: $showingDetail) {
Capsule()
.fill(Color.secondary)
.frame(width: 60, height: 4)
.padding(16)
AdminMapsView(isLongClickEnabled: true, hideLocationButton: false, latitude: self.$latitude, longitude: self.$longitude)
.padding(.top, 32)
}
.padding()
Button(action: {
if self.latitude > 0.0 && self.longitude > 0.0 && !self.titlu.isEmpty && !self.detaliu.isEmpty {
databaseService.addEvent(title: self.titlu, details: self.detaliu, date: self.dateTime, lat: self.latitude, long: self.longitude)
self.showingAlert = true
self.titlu = ""
self.detaliu = ""
} else {
self.mandatory = true
}
}) {
Text("Add event")
.frame(maxWidth: .infinity)
.padding(10.0)
.overlay(
RoundedRectangle(cornerRadius: 10.0)
.stroke(lineWidth: 2.0)
)
}.padding(.top, 15)
.alert(isPresented: $showingAlert) {
Alert(title: Text("Felicitări"), message: Text("Mesajul a fost adăugat cu succes."), dismissButton: .default(Text("Închidere")))
}
.alert(isPresented: $mandatory) {
Alert(title: Text("Atenție"), message: Text("Toate campurile trebuie sa fie completate."), dismissButton: .default(Text("Închidere")))
}
Spacer()
}
.navigationBarTitle("Add Point")
.navigationBarHidden(true)
.padding()
}
}
}
struct AddEvent_Previews: PreviewProvider {
static var previews: some View {
AddEvent()
}
}