My View simply consists of an Image object at the top and a button beneath it, both contained within a vertical ScrollView. I need to somehow gradually keep resizing (making smaller) the image as the user scrolls down, and return it to its original size as the user scrolls back up. I wasnt able to find any way to get notified and therefore be able to run code when the user scrolls, so Im unsure how to approach this or if it is even possible at all with current SwiftUI. Something tells me a GeometryReader might be needed here, but I honestly wouldnt know where to put it in the first place & it seems, according to my research, that GeometryReaders should be avoided whenever possible, although I would definitely make use of them if they can help here.
Code couldnt be simpler as of now:
struct ContentView: View {
var body: some View {
ScrollView {
Image("Spaghetti")
.resizable()
.frame(width: 200, height: 300)
Button {
// do something
} label: {
Text("Send")
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(20)
}
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
.padding()
.multilineTextAlignment(.center)
}
}
}
Deployment target is iOS 15 so OS version isnt an issue at all.
Thanks!