UIGestureRecognizer - detecting tap and drag like trackpad

前端 未结 1 1952
陌清茗
陌清茗 2021-02-05 22:01

Is there any way to cascade UIGestureRecognizers to detect a tap and then drag. For example, I want to detect when the user taps and then drags his finger around.

This w

相关标签:
1条回答
  • 2021-02-05 22:33

    although i haven't found the solution the way i expected, i found a better solution.

    By just using UILongPressGrstureRecognizer, it is surprising that it is able to implement tap and drag.

    You have to:

    1. set the numberOfTapsRequired to 1 to detect the initial tap.
    2. set the minimumDuration something smaller to detect drags quicker without waiting

    e.g.:

    UILongPressGestureRecognizer *mouseDrag = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleDrag:)];
    mouseDrag.numberOfTapsRequired=1;
    mouseDrag.minimumPressDuration=0.05;
    [clickLeft requireGestureRecognizerToFail:mouseDrag];
    

    to handle the drag, you must determine the state to handle it appropriately as a continuous gesture.

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