使用DragGesture时ScrollView无法正常工作

问题描述

我正在为LazyVGrid使用ScrollView。为了达到按下按钮的效果,我正在使用DragGesture。但是ScrollView无法正确滚动。

视觉表示:

enter image description here

这是我的代码

struct ShowHint: View {
    
    @State var pressed: Int = -1
    var columns: [GridItem] = Array(repeating: .init(.flexible()),count: 5)
    
    var body: some View {
        
        ZStack{
            ScrollView(showsIndicators: false) {
                LazyVGrid(columns: columns,spacing: 30) {
                    ForEach(0..<500) { i in
                        Text("\(i)")
                            .padding(.vertical,10)
                            .frame(maxWidth: .infinity)
                            .background(Color.red.opacity(pressed == i ? 0.5 : 1))
                            .gesture(DragGesture(minimumdistance: 0)
                                        .onChanged() { _ in
                                            pressed = pressed == i ? -1 : i }
                                        .onEnded { _ in
                                            pressed = -1
                                        })
                            .overlay(Group {
                                        if pressed == i {
                                            ShowOnTopOfButton(theS: "\(i)")
                                                .offset(y: -50.0)
                                                .allowsHitTesting(false)
                                        }})
                    }
                }
            }
            .padding(.top,50)
            .padding(.horizontal,10)
        }
    }
}


struct ShowOnTopOfButton: View {
    
    var theS: String
    var body: some View {
        vstack {
            Text("\(theS)")
                .padding(15)
                .background(Color.blue)
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)