iOS高级手势:获取滑动方向向量 [英] iOS Advanced Gestures: Getting Swipe Direction Vector

查看:297
本文介绍了iOS高级手势:获取滑动方向向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览文档,似乎新的高级手势API无法确定滑动方向超出基本{left,right,up,down}。

Looking through the documentation, it seems that the new advanced gestures API doesn't determine the direction of a swipe beyond the basic { left, right, up, down }.

我需要滑动的起点和方向。

I need the start point of the swipe and the direction.

除了编码我自己之外还有其他方法来检索这个高级手势库从头开始基本的手势?

Is there anyway to retrieve this other than coding my own advanced gesture library from scratch out the basic gestures?

如果这是我唯一的选择,有人能指点我这样做的一些开源代码吗?

And if this is my only option, could anyone point me to some open source code that does this?

推荐答案

知道了!文档是 here ,在底部的 创建自定义手势识别器 下。

Got it! Documentation is here, under 'Creating Custom Gesture Recognizers' at the bottom.

基本上六个手势Apple提供了来自UIGestureRecognizer的所有派生,你可以用同样的方式制作自己的手势识别器。

Basically the six gestures Apple provides all derive from UIGestureRecognizer, and you can make your own gesture recogniser in the same way.

然后,在你的视图的init中,你连接你的识别器。并且只是挂起它的行为会自动重新路由传入的触摸事件。

then, inside your view's init, you hook up your recogniser. and just the act of hooking it up automatically reroutes incoming touch events.

实际上,默认行为是让你的识别器成为这些事件的观察者。这意味着您的视图会像以前一样获取它们,此外,如果您的识别器发现了一个手势,它将在您的视图中触发myCustomEventHandler方法(当您连接识别器时,您通过了它的选择器)。

Actually, the default behaviour is to make your recogniser an Observer of these events. Which means your view gets them as it used to, and in addition if your recogniser spots a gesture it will trigger your myCustomEventHandler method inside your view (you passed its selector when you hooked up your recogniser).

但有时你想阻止原始的触摸事件到达视图,你可以在你的识别器中摆弄它来做到这一点。因此将它视为观察者有点误导。

But sometimes you want to prevent the original touch events from reaching the view, and you can fiddle around in your recogniser to do that. so it's a bit misleading to think of it as an ' observer '.

还有一种情况,一种姿势需要吃另一种姿势。如果您的视图也准备好接受双击,那么您不能只发回一次。您必须等待双击识别器报告失败。如果成功,你需要单击失败 - 显然你不想再发回两个!

There is one other scenario, where one gesture needs to eat another. Like you can't just send back a single click if your view is also primed to receive double clicks. You have to wait for the double-click recogniser to report failure. and if it is successful, you need to fail the single click -- obviously you don't want to send both back!

这篇关于iOS高级手势:获取滑动方向向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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