How to set content to Top in ScrollView?

Viewed 512

I am trying to set the content Text("Test.....") inside the scroll view to the top. Without using .frame (maxHeight: 150) and the like. I just need to kick it up under Text ("123")) but nothing comes out. And while scrolling in all directions should work. This is just an example to understand how to do it technically. Guys who can help!

import SwiftUI

struct MainView: View {
var body: some View {
    NavigationView {
        content
    }
    .padding()
  }
}

private extension MainView {
var content: some View {
    VStack {
        ZStack(alignment: .topLeading) {
            ScrollView([.vertical, .horizontal]) {
                Text("TestTestTestTestTestTestTestTestTestTestTest")// set to top in content
                    .frame(height: 100)
                    .background(Color.green)
                    //.position(y: 0)
            }
            Text("123")
        }
        .background(Color.blue)
    }
  }
}
1 Answers

You can use .offset() for that

.offset(y: -230)

or

.offset(y: UIScreen.main.bounds.height * -0.28) // for responsive

enter image description here

Related