ScrollView positions content outside bounds

I'm trying to allow scrolling in both axes when the content is larger than the screen.


```

var body: some View {

ScrollView([.horizontal, .vertical]) {

Rectangle()

.foregroundColor(Color.red)

.frame(width: 500, height: 500)

}

```



1. The scroll view centers the content instead of beginning at the top-leading.

2. When scrolled to the trailing edge there's some whitespace (similarly the content bleeds past the leading edge.)


How do I fix the above issues?

Replies

There is always the same trick: embed in a VStack. Why ? Cannot tell.


Try this:


struct ContentView: View {
    var body: some View {
        ScrollView([.horizontal, .vertical]) {
            VStack {
                Rectangle()
                    .frame(width: 300, height: 500)
                    .foregroundColor(Color.red)
            }.frame(width: 400, height: 800, alignment: .topLeading)
        }
    }
}