iOS Advanced Gestures: Getting Swipe Direction Vector

∥☆過路亽.° 提交于 2019-12-18 04:41:28

问题


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?


回答1:


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

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

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

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!



来源:https://stackoverflow.com/questions/3809397/ios-advanced-gestures-getting-swipe-direction-vector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!