关于 .gesture拖动手势在 swift ui 中的问题

问题描述

我试图检测何时滑动此文本视图。代码编译得很好,但我无法在我的实际设备上触发滑动。当我滑动时,什么也没有发生。 Tap 似乎工作得很好。谁能让我知道我的代码做错了什么?

以防万一,我正在使用最新的 Xcode 在 swift 5.3 中开发手表操作系统应用程序。

var body: some View {

    Text(tempstring).onTapGesture { checkStateRoll() }
    .frame(maxWidth: .infinity,maxHeight: .infinity)
    .gesture(DragGesture(minimumdistance: 10,coordinateSpace: .global)
     .onEnded { value in
                            let horizontalAmount = value.translation.width as CGFloat
                            let verticalAmount = value.translation.height as CGFloat
                            
                            if abs(horizontalAmount) > abs(verticalAmount) {
                                horizontalAmount < 0 ? leftswipe() : rightswipe()
                            } else {
                                verticalAmount < 0 ? upswipe() : downswipe()
                            }
                            tempstring = String(numdice) + "d" + String(typesofdice[typedice])
                            speaknumber()
                        }        ) 
    
    .background(progstate == 2 ? Color.blue : Color.red)
    }
}

非常感谢您的帮助。这让我难受了好几个星期。

解决方法

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

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

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