This is driving me nuts. There seems to be new behaviour for handling background images in iOS14.
Desired effect is: a fixed background image that fills the screen, ignoring the safe areas, and is totally static when the keyboard pops up. Instead the keyboard makes the image slide to the right, even though the keyboard is rising from the bottom (??).
Is this a SwiftUI bug? Any ideas/workarounds appreciated.
The code to produce this is very small:
import SwiftUI
struct ContentView: View {
@State var name = "Name"
var body: some View {
GeometryReader { geometry in
VStack {
TextField("Placeholder", text: $name)
}
.frame(width: geometry.size.width, height: geometry.size.height)
.background(
Image("bricks")
.resizable()
.scaledToFill()
.edgesIgnoringSafeArea(.all)
)
}
}
}
Ok, it turns our that adding the .frame
call as follows allows the the background image to display as desired.
(Note specifically that the .frame
call omits the height
argument. In many previous tries to solve this the height was included, leading to the different undesired behaviour)
.background(
Image("bricks")
.resizable()
.scaledToFill()
.frame(width: geometry.size.width)
.edgesIgnoringSafeArea(.all)
)