gpt4 book ai didi

swiftui - 如何检测 SwiftUI 中的点击位置?

转载 作者:行者123 更新时间:2023-12-01 23:25:18 26 4
gpt4 key购买 nike

我想打印 <#code#> block 中点击点的位置(x,y 坐标)以及我的 View 尺寸。

struct ContentView: View {
var body: some View {
self.onTapGesture {
<#code#>
}
}
}

最佳答案

DragGestureminimumDistance: 0 添加到您的 body ,示例:

var body: some View {
VStack
{

}
.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)
.background(Color.red)
.gesture(DragGesture(minimumDistance: 0).onEnded({ (value) in
print(value.location)
}))
}

关于swiftui - 如何检测 SwiftUI 中的点击位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67346328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com