3. 识别SWiftUI中的点击位置
1. iOS17上有对应的方法
.onTapGesture { location in
// 获取点击位置
tapLocation = location
print("点击位置: \(location)")
}
兼容iOS14的内容要自己去实现,通过手势的判断时间或者点的位置长短
.gesture(
DragGesture(minimumDistance: 0) // 最小距离为 0,模拟点击
.onEnded { value in
// 获取点击位置
tapLocation = value.location
print("点击位置: \(tapLocation)")
}
)
Last updated