gpt4 book ai didi

swift - 如何检测EdgePan Gesture SwiftUI

转载 作者:行者123 更新时间:2023-11-28 05:39:15 24 4
gpt4 key购买 nike

我正在尝试从 SwiftUI 的左侧识别 EdgePan。我知道有一些手势,但无法将它们应用到整个屏幕。 (尝试使用 DragGesture)。是否可以在 SwiftUI 中实现 EdgePan?或者我如何使用 DragGesture 来做同样的事情?

最佳答案

是的,这可以通过 DragGesture 实现。

DragGesture 有一个 startLocation 属性,它是一个 CGPoint。由此,您可以检测手势从哪里开始,并使用它来确定它是否从边缘开始。

拿你现有的DragGesture,在.onChanged闭包中,传入gesture,用gesture找到开始位置.startLocation。由于您想要检测边缘,因此您需要 gesture.startLocationx 属性。

看起来像这样:

DragGesture()
.onChanged({gesture in
if gesture.startLocation.x < CGFloat(100.0){
print("edge pan")
}
}
)

关于swift - 如何检测EdgePan Gesture SwiftUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57497501/

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