Ios 使用Swift UI在水平滚动中捕捉到边缘?

Ios 使用Swift UI在水平滚动中捕捉到边缘?,ios,swift,swiftui,Ios,Swift,Swiftui,如何在SwiftUI滚动视图中水平滚动/拖动时将列表捕捉到边缘 struct RowView: View { var post: Post var body: some View { GeometryReader { geometry in VStack { Text(self.post.title) Text(self.post.description)

如何在SwiftUI滚动视图中水平滚动/拖动时将列表捕捉到边缘

struct RowView: View {
    var post: Post
    var body: some View {
        GeometryReader { geometry in
            VStack {
                Text(self.post.title)
                Text(self.post.description)
            }.frame(width: geometry.size.width, height: 200)
            //.border(Color(#colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1)))
            .background(Color(#colorLiteral(red: 0.721568644, green: 0.8862745166, blue: 0.5921568871, alpha: 1)))
            .cornerRadius(10, antialiased: true)
            .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
        }
    }
}
列表视图

struct ListView: View {
    var n: Int
    @State var posts = [Post(id: UUID(), title: "1", description: "11"),
                        Post(id: UUID(), title: "2", description: "22"),
                        Post(id: UUID(), title: "3", description: "33")]

    var body: some View {
        GeometryReader { geometry in
            ScrollView {
                ForEach(0..<self.n) { n in
                    RowView(post: self.posts[0])
                    //.border(Color(#colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)))
                    .frame(width: geometry.size.width, height: 200)
                }
            }
        }
    }
}
struct ContentView: View {
    init() {
        initGlobalStyles()
    }

    func initGlobalStyles() {
        UITableView.appearance().separatorColor = .clear
    }

    var body: some View {
        GeometryReader { geometry in
            NavigationView {
                ScrollView(.horizontal) {
                    HStack {
                        ForEach(0..<3) { _ in
                            ListView(n: 1000)  // crashes
                                .frame(width: geometry.size.width - 60)
                        }
                    }.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 0))
                }.gesture(DragGesture().onEnded({ value in
                    print("drag end: \(value)")  // not printing
                }))
            }
        }
    }
}

我已经在滚动视图中添加了
DragGesture().oneded()
,但在拖动端没有调用它。

嘿,你做到了吗?我使用了
UIKit
,让它工作了。