iphone sdk如何捕捉1秒后的长按?

发布于 2024-12-01 18:06:33 字数 100 浏览 3 评论 0原文

我正在使用 UILongPressGestureRecognizer 来捕获长按事件。问题是我只能在用户松开手指后才能响应。

如何实现一个在用户按住 x 秒后响应的功能?

I'm using UILongPressGestureRecognizer to catch a Long Press event. The problem is I can only respond to it after user release his finger.

How do I implement a function that will respond after user hold for x seconds?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼趣 2024-12-08 18:06:33

UILongPressGestureRecognizer 适用于此,再次检查您的代码并将长按持续时间设置为 -

[longPressGesture setMinimumPressDuration:<#(CFTimeInterval)#>];

UILongPressGestureRecognizer works for this, check your code again and set duration for long press as -

[longPressGesture setMinimumPressDuration:<#(CFTimeInterval)#>];
表情可笑 2024-12-08 18:06:33

不使用手势识别器,而是使用 UIView 实例方法touchesBegan:withEvent:、touchesMoved:withEvent: 和touchesEnded:withEvent:。虽然它们不像使用手势识别器那么方便,但您可以完全控制触摸解释。

请注意,如果您每次尝试使用这些来解释多点触控手势,则触摸屏会“有弹性”,因为报告的触摸次数会在触摸事件处理期间发生变化。我的应用程序将捏合解释为向我报告的一根手指和两根手指触摸的随机序列。我成功地消除了它的抖动,但正确地编写代码才是真正的 PITA。

Instead of using a gesture recognizer, use the UIView instance methods touchesBegan:withEvent:, touchesMoved:withEvent: and touchesEnded:withEvent:. While they're not as convenient as using a gesture recognizer, you have complete control of the touch interpretation.

Note that if you every try to use these to interpret multitouch gestures, the touch screen is "bouncy", in that the reported number of touches will vary during the touch event processing. My app interprets pinches, which are reported to me as a random sequence of one and two finger touches. I managed to debounce it, but getting the code right was a real PITA.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文