I’ve a really primary view that has a background (Colour.pink
) and a few content material inside a ScrollView
. The view labored nice till I observed one thing. After choosing the textual content discipline and tappint on the background, the keyboard wasn’t dismissing. Even when I clicked someplace that had nothing visually (anticipate the background) it nonetheless did not work.
struct ContentView: View {
@State personal var filter = ""
var physique: some View {
ZStack {
Colour.pink.ignoresSafeArea(.all)
.onTapGesture {
// Dismiss keyboard
}
ScrollView {
VStack(spacing: 8) {
TextField("Some Filter", textual content: $filter)
.textFieldStyle(.roundedBorder)
Button("clicky click on") {
// Fetch information
}
.buttonStyle(.borderedProminent)
// Different information consequence associated stuff
}
}
.refreshable {
// Fetch information
}
}
}
}
So to unravel it I attempted doing these beneath:
-
I attempted so as to add
.allowsHitTesting(false)
but it surely utterly bricked the scroll view.
(Anticipated) -
I attempted so as to add a invisible view to the scroll view that did the identical factor. Nevertheless it grew to become tiny. I attempted to pressure it to be huge however the scroll view grew to become scrollable right down to nothingness.
-
I attempted so as to add it as a dynamic footer (the dynamicly streching ones). This labored, but it surely was approach too expensive for what it was doing. And it approach too overcomplicated my view.
I am operating iOS 15. And I am in search of an answer that is not too difficult. Thanks upfront.