结合长按手势和拖动手势

结合长按手势和拖动手势

本文介绍了结合长按手势和拖动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在移动我的观点

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveRight:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[bubbleView[rightCnt] addGestureRecognizer:panRecognizer];
[panRecognizer release];

现在,我希望通过长按拖动来做同样的事情。

Now , I want to do same thing by drag with long press.

任何想法?

推荐答案

UILongPressGestureRecognizer 已经做了你想要的。看一下 UIGestureRecognizerState 属性。来自:

UILongPressGestureRecognizer already does what you want for you. Take a look at the UIGestureRecognizerState property. From the documentation:

因此,基本上在调用 UILongPressGestureRecognizer 选择器之后,您将收听UIGestureRecognizerStateBegan,UIGestureRecognizerStateChanged,UIGestureRecognizerStateEnded。在 UIGestureRecognizerStateChanged 期间继续更改视图框架。

So essentially after your UILongPressGestureRecognizerselector is called you listen to UIGestureRecognizerStateBegan, UIGestureRecognizerStateChanged, UIGestureRecognizerStateEnded. Keep changing your views frame during UIGestureRecognizerStateChanged.

- (void)moveRight:(UILongPressGestureRecognizer *)gesture
{
    if(gesture.state == UIGestureRecognizerStateBegan)
    {
        //if needed do some initial setup or init of views here
    }
    else if(gesture.state == UIGestureRecognizerStateChanged)
    {
        //move your views here.
        [yourView setFrame:];
    }
    else if(gesture.state == UIGestureRecognizerStateEnded)
    {
        //else do cleanup
    }
}

这篇关于结合长按手势和拖动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:59