For example
struct TestView: View {
let url = "https://ts1.cn.mm.bing.net/th/id/R-C.3da9ce39e8e1f19875002d44dcf26244?rik=sYOvBjjpRUOkng&pid=ImgRaw&r=0"
@State var touchedIndex: Int = 0
var body: some View {
VStack {
Text("touched index : \(touchedIndex)")
ScrollView(.horizontal) {
HStack {
ForEach(0..<10) { index in
Text("index: \(index)")
.onTapGesture {
touchedIndex = index
}
}
}
.frame(height: 50)
}
AsyncImage(url: URL(string: url)) { image in
image
.resizable()
.scaledToFill()
.frame(width: UIScreen.main.bounds.size.width, height: 200)
.clipped()
.contentShape(Rectangle())
} placeholder: {
ProgressView()
}
.frame(width: UIScreen.main.bounds.size.width, height: 200)
.clipped()
.contentShape(Rectangle())
}
}
}
#Preview(body: {
TestView()
})
The content in ScrollView is clickable but cannot be scrolled horizontally