我想打印 <#code#> 块中点击点的位置(x,y 坐标)以及我的视图尺寸。
struct ContentView: View {
var body: some View {
self.onTapGesture {
<#code#>
}
}
}
答案 0 :(得分:3)
将 DragGesture
和 minimumDistance: 0
添加到您的身体中,例如:
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)
}))
}