[英]How to detect EdgePan Gesture SwiftUI
我試圖從 SwiftUI 的左側識別 EdgePan。 我知道有一些手勢,但無法將它們應用於整個屏幕。 (嘗試使用 DragGesture)。 是否可以在 SwiftUI 中實現 EdgePan? 或者我如何使用 DragGesture 來做同樣的事情?
是的,這可以通過DragGesture
。
DragGesture
有一個startLocation
屬性,它是一個CGPoint
。 由此,您可以檢測手勢的開始位置,並使用它可以確定它是否從邊緣開始。
使用現有的DragGesture
,並在.onChanged
閉包中,傳入gesture
,並使用gesture.startLocation
找到起始位置。 由於您想檢測邊緣,因此您需要gesture.startLocation
的x
屬性。
它看起來像這樣:
DragGesture()
.onChanged({gesture in
if gesture.startLocation.x < CGFloat(100.0){
print("edge pan")
}
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.