Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop vertical scroll in SwiftUI ScrollView

I have tried to implement a scrollView using swiftUI. Inside the scrollview there is a horizontal stack(HStack) containing another view. I wanted the scrollview to scroll horizontally. But it also scrolls vertically. Following is my code:

struct categoryRow : View {
var categoryName: String
var landmarks : [Landmark]
var body: some View {
    VStack(alignment: .leading){
        Text(categoryName).font(.headline).padding(EdgeInsets(top: 15, leading: 10, bottom: 0, trailing: 0))
        ScrollView (alwaysBounceHorizontal: true, showsHorizontalIndicator: false, showsVerticalIndicator: false ){
            HStack(spacing: 15){
                ForEach(landmarks) { landmark in
                    NavigationButton(destination: LandMarkDetails(landmark: landmark)) {
                        CategoryItem(landmark: landmark)
                    }
                }
            }.padding()
        }.frame( height: 190)
    }
}
}

I could not find any option yet to stop the vertical scrolling. What am I missing here?

like image 953
Rubaiyat Jahan Mumu Avatar asked Jul 04 '19 05:07

Rubaiyat Jahan Mumu


1 Answers

If ScrollView's height is less than the content's height it will scroll vertically too.

Just make it higher or the content narrower.

like image 111
Bogdan Farca Avatar answered Sep 25 '22 21:09

Bogdan Farca