为什么UIPanGestureRecognizer无法在iOS 7的屏幕顶部工作?

时间:2013-10-16 17:03:03

标签: iphone ios uikit uigesturerecognizer uipangesturerecognizer

我在UICollectionViewCell子类中创建了一个UIPanGestureRecognizer。它适用于除屏幕顶部以外的所有单元格。关于状态栏的高度,平移手势识别器已经死亡。它不会开火。我的测试应用程序只有一个UICollectionView,没有别的。没有状态栏。我想也许这与通知中心“活动边缘”窃取触摸事件有关。

_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
_panGestureRecognizer.delegate = self;
_panGestureRecognizer.maximumNumberOfTouches = 1;
[self addGestureRecognizer:_panGestureRecognizer];

当我在单元格中平移时,在屏幕顶部,我在平移开始时没有收到任何消息。在我抬起手指之前没有呼叫回叫。然后回调接收BEGAN,之后立即收到ENDED。

- (void)panGestureRecognized:(UIPanGestureRecognizer*)sender {
    NSLog(@"pan detected"); // for first cell, only called when finger is lifted up.

    if (sender.state == UIGestureRecognizerStateBegan) {
        NSLog(@"BEGAN");
    } else if (sender.state == UIGestureRecognizerStateEnded) {
        NSLog(@"ENDED");
    }
}

单元格是手势识别器的代表。它实现了:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

单元格也会覆盖UIView方法:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    return YES;
}

这是屏幕顶部的平移手势识别器的已知问题吗?是否有解决方法?

0 个答案:

没有答案