iOS Advanced Gestures: Getting Swipe Direction Vector

后端 未结 1 1690
陌清茗
陌清茗 2020-12-17 16:40

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 }.

<
1条回答
  •  一整个雨季
    2020-12-17 17:26

    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!

    0 讨论(0)
提交回复
热议问题