SwiftUI – Tastaturvermeidung verschiebt Inhalte in die NavigationsleisteIOS

Programmierung für iOS
Anonymous
 SwiftUI – Tastaturvermeidung verschiebt Inhalte in die Navigationsleiste

Post by Anonymous »

Ich habe eine Ansicht mit einigen Textfeldern. Wenn Sie das obere Textfeld auswählen, wird durch die Tastaturumgehung alles nach oben verschoben, damit das untere Textfeld sichtbar bleibt. In diesem Fall wird der Text „Eingabe 1“ über dem oberen Textfeld in die Navigationsleiste verschoben und ausgeblendet.

Code: Select all

struct Settings: View {
@State private var input1: String = ""
@State private var input2: String = ""
@State private var input3: String = ""
@State private var input4: String = ""
@State private var input5: String = ""

init() {
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithTransparentBackground()
coloredAppearance.backgroundColor = .gray

UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().compactAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
}

var body: some View {
NavigationView {
VStack(spacing: 16) {
Group {
VStack {
Text("Input 1")
.frame(maxWidth: .infinity, alignment: .leading)
TextField("", text: $input1)
.disableAutocorrection(true)
.padding()
.overlay(RoundedRectangle(cornerRadius: 5).stroke(.gray))
}
}
Group {
VStack {
Text("Input 2")
.frame(maxWidth: .infinity, alignment: .leading)
TextField("", text: $input2)
.disableAutocorrection(true)
.padding()
.overlay(RoundedRectangle(cornerRadius: 5).stroke(.gray))
}
}
Group {
VStack {
Text("Input 3")
.frame(maxWidth: .infinity, alignment: .leading)
TextField("", text: $input3)
.disableAutocorrection(true)
.padding()
.overlay(RoundedRectangle(cornerRadius: 5).stroke(.gray))
}
}
Group {
VStack {
Text("Input 4")
.frame(maxWidth: .infinity, alignment: .leading)
TextField("", text: $input4)
.disableAutocorrection(true)
.padding()
.overlay(RoundedRectangle(cornerRadius: 5).stroke(.gray))
}
}
Spacer()
}
.navigationBarTitle("Header", displayMode: .inline)
}
.ignoresSafeArea()
}
}
Ohne Tastatur
Mit Tastatur
Hat jemand eine Möglichkeit, dies zu verhindern? Ich habe es mit Abstandshaltern versucht, ohne Erfolg. Dadurch bleibt der Text zwar sichtbar, es entsteht jedoch ein Abstand zwischen der Navigationsleiste und dem Text, wenn die Tastatur nicht geöffnet ist. Ich habe auch versucht, damit herumzuspielen 

Code: Select all

ignoresSafeArea(.keyboard)
.
Wenn das obere Textfeld ausgewählt ist, sollte die Tastatur idealerweise die unteren Textfelder abdecken, ohne etwas nach oben zu drücken. Ich möchte Inhalte nur bei Bedarf nach oben verschieben, um das aktuell ausgewählte Textfeld sichtbar zu halten. Hat jemand eine Möglichkeit, dies zu tun? Vielen Dank im Voraus.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post