返回应用程序后,LongPressGesture停止调用操作

时间:2014-05-25 23:31:23

标签: ios touch sprite-kit uigesturerecognizer

我目前正在使用SpriteKit进行游戏并使用UILongPressGesture,因为我只想一次识别一次触摸并想要同时处理水龙头和滑动。游戏运行正常,但如果应用程序处于停留状态或设备处于休眠状态(更一致,这是应用程序进入休眠状态时),返回游戏后,我在initWithTarget:action:中为其指定的操作是如果手指滑动或快速滑动,则根本不被调用。

如果我点击,它会被调用。如果我点击,保持一点,然后开始滑动我的手指,它会间歇性地调用,而不是像一个新的应用程序开始时一样。另一个问题是它并不总是发生,而且(看似)只是修复了它自己。

代码:

// The recognizer
_tapRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(recognizeTheTap:)];
[_tapRecognizer setNumberOfTapsRequired:0];
[_tapRecognizer setNumberOfTouchesRequired:1];
[_tapRecognizer setMinimumPressDuration:0];
_tapRecognizer.allowableMovement = 0;
[_tapRecognizer setDelegate:self];
[self.view addGestureRecognizer:_tapRecognizer];

// The action
-(void)recognizeTheTap:(UIGestureRecognizer*)recognizer{
    NSLog(@"Recognizing The Tap");
    CGPoint thePoint = [recognizer locationInView:recognizer.view];
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        NSLog(@"Tap began");
        [self handleTapBegan:thePoint];
    } else if (recognizer.state == UIGestureRecognizerStateChanged){
        NSLog(@"Tap changing?");
        [self handleTapMoved:thePoint];
    } else if (recognizer.state == UIGestureRecognizerStateEnded){
        NSLog(@"Tap ended.");
        [self handleTapEnded:thePoint];
    } else if (recognizer.state == UIGestureRecognizerStateCancelled){
        NSLog(@"Tap canceled");
        [self handleTapEnded:thePoint];
    } else if (recognizer.state == UIGestureRecognizerStateFailed){
        NSLog(@"Tap failed");
    } else {
        NSLog(@"WHAT IS THIS?\n%@", recognizer);
    }
}

进一步挖掘似乎正在进行gestureRecognizer: shouldReceiveTouch:仍然会被调用,但gestureRecognizerShouldBegin:

可能的“回答”?

iAd弹出,我点击了它,并且大部分点击都没有加载。最终确实如此。在评论出添加UILongPressGestureRecognizer后,iAd加载没有问题。我实现了touchesBegan:withEvent:和其他人,让他们调用我的handleTapWhatever函数,但还没有能够再次发生错误。

所以我认为它与this有关,但是用touchesBegan:withEvent:处理它对我来说很好,这似乎是目前最安全的选择。

0 个答案:

没有答案