gpt4 book ai didi

ios - 如何在 .Ended 状态下访问 Pan Gesture 的初始点

转载 作者:行者123 更新时间:2023-11-28 16:09:14 25 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现一个平移手势,我需要在其中访问处于 .Ended 状态的初始点。

这是代码。

func handleTestViewTap (panRecognizer: UIPanGestureRecognizer){

var locationOfBeganTap: CGPoint?

if panRecognizer.state == UIGestureRecognizerState.Began {
locationOfBeganTap = panRecognizer.locationInView(view)
print("locationOfBeganTap in BEGAN State -> .\(locationOfBeganTap)")

} else if panRecognizer.state == UIGestureRecognizerState.Ended {
print("locationOfBeganTap -> .\(locationOfBeganTap)")
print("locationOfBeganTap in ENDED State -> .\(locationOfBeganTap)")

}
}

现在,这是输出:

locationOfBeganTap in BEGAN State -> .Optional((195.5, 120.0))
locationOfBeganTap in ENDED State -> .nil

我无法理解为什么 locationOfBeganTap.Ended 状态下为 nil

有人可以分享代码以在 .Ended 状态下访问 locationOfBeganTap...

最佳答案

您这样做的方式行不通。相反,在最后计算它:

func handleTestViewTap (panRecognizer: UIPanGestureRecognizer){

if panRecognizer.state == UIGestureRecognizerState.Ended {
print("locationOfBeganTap -> (.\(touch.locationInView(view).x - touch.translationInView(view).x), .\(touch.locationInView(view).y - touch.translationInView(view).y))")
print("location in ENDED State -> .\(touch.locationInView(view))")
}
}

关于ios - 如何在 .Ended 状态下访问 Pan Gesture 的初始点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39793491/

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