0

所以我实现了一个单指长按手势识别器,但识别器似乎总是缺少 UIGestureRecognizerStateBegan 状态...如果我长按不移动手指并抬起,我会收到 StateEnded 调试消息。如果我长按并稍微移动手指然后抬起,我会收到 StateChanged 和 StateEnded 调试消息。但我从未见过 StateBegan。

UIPanGestureRecognizer 没有这个问题 - Pan 从 Began->Changed->Ended 获取所有正确的手势状态。

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
    CGPoint location = [recognizer locationInView:self];

    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            NSLog(@"!!!!handleLongPress: StateBegan !!!!!");
            break;
        case UIGestureRecognizerStateChanged:
            NSLog(@"!!!!handleLongPress: StateChanged !!!!!");
            break;
        case UIGestureRecognizerStateEnded:
            NSLog(@"!!!!handleLongPress: StateEnded !!!!!");
            break;
        default:
            break;
    }   
}
4

1 回答 1

1

I was having a similar problem and it was caused by the UILongPressGestureRecognizer setup: the original sample code I was using specified the numberOfTapsRequired = 1, and I had to quick-tap and release, and THEN long-tap to make it work, instead of just tapping and holding for a couple of seconds. When I removed the numberOfTapsRequired the code now behaved as I expected. Hope this helps =)

于 2011-09-05T19:48:40.477 回答