如何用 UIGestureRecognizer 替换 TouchesBegan [英] How to replace TouchesBegan with UIGestureRecognizer

查看:31
本文介绍了如何用 UIGestureRecognizer 替换 TouchesBegan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题来了:我想在我的应用程序中使用 UIGestureRecognizer.出于这个原因,我想从我的观点中放弃 TouchBegan/TouchEnded 事件.

here's the problem: I'd like to move to using UIGestureRecognizer in my Apps. For this reason I'd like to ditch TouchBegan/TouchEnded event's from my views.

但是我不明白如何使用 UIGestureRecognizers 管理触摸开始(用户将手指放在屏幕上)的时间.

However I don't understand how to manage when the touch began (user puts its finger on the screen) with UIGestureRecognizers.

最简单的一个是 UITapGestureRecognizer 但关联的选择器只有在 TapGesture 完成时才会被触发(嗯......当然完全有道理).但问题仍然存在:我怎样才能停止使用 touchesBegan 并从 UIGestureRecognizer 中获取该事件?

The simplest one is UITapGestureRecognizer but the selector associated gets fired only when the TapGesture is completed (Well... it makes completely sense of course). But still the problem remains: how can I stop using touchesBegan and get that event anyway from UIGestureRecognizer?

谢谢!

推荐答案

对于您尝试做的事情,您做不到.手势识别器用于高级手势,因此它们在所有应用程序中的行为都相同(想想滑动、双击所需的时间等).对于低级控制和识别器无法执行的操作,您仍然需要在 touchesbegan、touchesEnded 等中实现逻辑.

For what you are tryin ti do you can't. The gesture recoginizers are for high level gestures so they behaive the same across all apps (think swipes, the timing required for a double tap, etc). For low level control and to do things that the recognizers can't you will still have to implement logic in touchesbegan, touchesEnded, etc.

这篇关于如何用 UIGestureRecognizer 替换 TouchesBegan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆