I want my ScrollView to dynamically adjust its size based on the content, without altering the overall view layout. Additionally, I want to be able to scroll up and down in the view (persist its position) without it bouncing back to its original position.
import SwiftUI
struct ContentView: View {
@State var scrollViewContentSize: CGSize = .zero
var body: some View {
let _ = ContentView._printChanges()
VStack {
Text("Header")
ScrollView {
VStack {
Text("IOS Dev")
Text("SwiftUI")
}
.background(
GeometryReader { geo in
Color.blue.task {
scrollViewContentSize = geo.size
print(scrollViewContentSize)
}
}
)
}
.frame(width: scrollViewContentSize.width,
height: scrollViewContentSize.height,
alignment: .center)
.background(Color.red)
Text("Footer")
}
}
}
#Preview {
ContentView()
}
the issue is IOS DEV and SwiftUI are not visible because when i added frame modifier to scrollView, scrollViewContentSize.width is becoming zero.
Give me solution based on IOS 15 or before not later.