[英]How to navigate through SwiftUI TextFields by clicking on return button from keyboard?
[英]SwiftUI Software keyboard + two TextFields = Constraint conflict
TL;博士
在鍵盤顯示時點擊第二個TextField
會觸發約束沖突。
細節
下面的代碼可以按原樣運行。 點擊頂部的TextField
,然后點擊下面的。 Xcode 控制台報告了這一點(為清楚起見進行了刪節):
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
<'assistantHeight' TUISystemInputAssistantView.height == 44 (active)>
<'assistantView.bottom' TUISystemInputAssistantView.bottom == _UIKBCompatInputView.top (active)>
<'assistantView.top' V:|-(0)-[TUISystemInputAssistantView] (active, names: '|':UIInputSetHostView )>
<'inputView.top' V:|-(0)-[_UIKBCompatInputView] (active, names: '|':UIInputSetHostView )>
Will attempt to recover by breaking constraint
<'assistantView.bottom' ...>
問題
AFAIK 我無法控制這四個約束中的任何一個。 有沒有辦法避免這種情況? 我還應該擔心嗎?
代碼
struct ContentView: View {
@State private var text1 = ""
@State private var text2 = ""
var body: some View {
VStack {
TextField("Tap here first...", text: $text1)
.background(Color.white).padding()
TextField("...then tap here", text: $text2)
.background(Color.white).padding()
Spacer()
}.background(Color.gray)
}
}
GeometryReader.init { geometry in ScrollView.init { VStack.init(alignment: .leading, spacing: nil, content: { Text("Hello.").font(.custom("Helvetica-Bold", size: 32)) Text("This just my sample application using swift UI").padding(.init(top: 0, leading: 0, bottom: 0, trailing: (geometry.size.width * 0.35))).foregroundColor(.gray) TextField.init("Email Address", text: self.$textFieldName).frame(width: geometry.size.width, height: 50).disableAutocorrection(true).layoutPriority(1000) TextField.init("Email Address", text: self.$textFieldName).frame(width: geometry.size.width, height: 50).disableAutocorrection(true).layoutPriority(1000) }) } }
如果您好奇會發生什么限制它,因為您的鍵盤具有自動更正功能。
使用這條線,
.disableAutocorrection(<#Bool?#>)
擺脫鍵盤頂部的自動更正選項卡。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.