2

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 Answers1

0

You can use .offset() for that

.offset(y: -230)

or

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

enter image description here

Taeeun Kim
  • 964
  • 1
  • 8
  • 20
  • Hello! In my application, the content can be of different sizes, so you need to calculate automatically and not fit a certain size. So far, the answer does not fit. – Paul Lochte Jun 30 '21 at 20:11