我正在尝试检测此文本视图何时已被滑动。代码编译得很好,但我无法在我的实际设备上触发滑动。当我刷卡的时候,什么都不会发生。水龙头似乎运转得很好。有人能让我知道我的代码做错了什么吗?
为了防止这件事发生,我正在用最新的Xcode开发一个在Quick5.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)
}
}非常感谢你的帮助。这几个星期来一直困扰着我。
发布于 2021-01-13 03:42:49
几件事:
,
下面是一个示例操场:
import SwiftUI
import PlaygroundSupport
struct V: View {
var body: some View {
ZStack {
Color.red
Text("Test")
}
.onTapGesture { print("tap") }
.gesture(DragGesture(minimumDistance: 10, coordinateSpace: .global).onEnded { print($0)})
}
}
let host = UIHostingController(rootView: V().frame(width: 500.0, height: 500.0))
host.preferredContentSize = CGSize(width: 300, height: 300)
PlaygroundPage.current.liveView = hosthttps://stackoverflow.com/questions/65685760
复制相似问题