1

我有一个UIImageViewwith a UILongPressGestureRecognizer,当检测到长按时会发送一个动作。

我确实在UIImageView. 但是,我也有一种手动滚动,UIImageView可以使用touchesBeganandtouchesMoved方法移动。

当用户交互被禁用时,只有滚动起作用。启用用户交互后,只有长按手势识别器起作用。

我怎样才能使两者同时工作?

如有必要,可以共享代码,但我认为这个问题不需要它。

4

3 回答 3

3
UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
[gestureRecognizer addTarget:self action:@selector(imgLongPressed:)];
gestureRecognizer.delegate = self;
[imgview addGestureRecognizer: gestureRecognizer];

- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
    UIImageView *view_ =(UIImageView*) sender.view;
    CGPoint point = [sender locationInView:view_.superview];

    if (sender.state == UIGestureRecognizerStateBegan)
    {

    }
    else if (sender.state == UIGestureRecognizerStateChanged)
    {

    }
    else if (sender.state == UIGestureRecognizerStateEnded)
    {

    }

}
于 2013-07-24T12:54:02.087 回答
0

手势识别器总是优先考虑并覆盖touchesBegan:样式事件。您必须使用相同的 API/技术来实现这两种行为。

于 2013-07-24T11:53:27.877 回答
0

首先,您必须使用手势来移动图像,如下所示。

 UIPanGestureRecognizer  *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[vwBigImage addGestureRecognizer:panRecognizer];

将被调用的函数如下所示..

 -(void)move:(id)sender {

CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:yourview];

if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
    _firstX = [yourimageview center].x;//declare CGFloat _firstX; in .h file

    _firstY = [yourimageview center].y;//declare CGFloat _firstY; in .h file
}

translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
[yourimageview setCenter:translatedPoint];

}

现在你的两个手势都会被调用。

让我知道它是否有效!

编码快乐!!!!

于 2013-07-24T11:56:35.633 回答