我想在用户从屏幕底部开始平移时获取第一次触摸的位置,然后才读取位置并使用它。
我知道我可以检查.begin
状态,但如果这种情况为真,我不知道如何跟踪平底锅。这似乎是一件很容易的事情,但我没有设法做到。
@objc private func handleSwipe(swipe: UIPanGestureRecognizer) {
if swipe.state == .began && swipe.location(in: self.view).y < self.view.frame.height * 0.15 {
// do something with swipe.translation(in: self.view).y
}
}
只需将坐标存储在变量中,并在处理 .changed 状态时检索它。所有手势识别器回调都在主线程上,因此在这些回调之间维护自己的状态应该不会有问题。