0

我有一个UIView并且我在视图上添加了UILongGestureRecognizerUIPanGestureRecognizer。当我点击并按住它几秒钟时,我得到了 LongPress 识别的回调。

代码如下图

- (void)addPanGsetureForView:(UIView *)object
{    
    UIPanGestureRecognizer * panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognised:)];
    [object addGestureRecognizer:panGesture];
    [panGesture release];
}

- (void)addLongPressGsetureForView:(UIView *)object
{
    UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(imageLongPressed:)];
    [longPress setMinimumPressDuration:1.0];
    [object addGestureRecognizer:longPress];
    [longPress release];
}

所以我想使用平移手势移动视图。因此,当在视图上没有移开手指的情况下识别出长按时,我希望平移手势得到识别。如果我移开手指并再次点击并平移它,它就会被识别。
所以请帮我解决这个问题
提前致谢

4

1 回答 1

4

取自 Apple 关于手势识别器的文档

允许同时手势识别

默认情况下,没有两个手势识别器可以尝试同时识别他们的手势。gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:但是您可以通过实现协议的可选方法来更改此行为UIGestureRecognizerDelegate。当接收手势识别器的识别会阻止指定手势识别器的操作时调用此方法,反之亦然。返回 YES 以允许两个手势识别器同时识别他们的手势。

刚刚对此进行了测试,我认为它将解决您的问题!

于 2012-08-20T07:42:05.490 回答