我的观点由

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

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

任何的想法?

最佳答案

UILongPressGestureRecognizer已经可以满足您的需求。看一看UIGestureRecognizerState属性。从documentation:



因此,从本质上讲,在调用UILongPressGestureRecognizer选择器之后,您将监听UIGestureRecognizerStateBegan,UIGestureRecognizerStateChanged,UIGestureRecognizerStateEnded。在UIGestureRecognizerStateChanged期间不断更改 View 框架。

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

关于iphone - 组合长按手势和拖动手势,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9272333/

10-10 20:29