保持触摸会延迟我的游戏吗? UIGestureEnvironmentSortAndSendDelayedTouches?

时间:2019-06-10 07:42:27

标签: ios cocos2d-iphone uigesturerecognizer

我在应用商店中有一个iOS cocos2d(v2)游​​戏,虽然我多年没有更新,但是最近发现了一个错误并需要对其进行修复。这需要我经历所有使应用程序构建在现代版本的XCode上的痛苦。当我一切都准备好并准备将补丁提交到应用商店后,我意识到当我的应用实际检测到用户已经触摸并保持在屏幕上的位置时,这是一个荒谬的缓慢的时间延迟。

在查看调用堆栈时,如果我快速点击屏幕,那么一切都很好,并且我的断点也很快被击中:

enter image description here

但是,如果我触摸并按住屏幕,则在达到断点之前几乎要延迟一秒钟,并且调用堆栈看起来像: enter image description here

我的问题是,如何关闭此行为,以使没有延迟的触摸或呼叫UIGestureEnvironmentSortAndSendDelayedTouches?换句话说,我需要触摸并按住屏幕才能立即触发事件,这与快速点击时完全相同。

更新

这是完整的堆栈跟踪:

 * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
     frame #0: 0x0000000100e79ab0 mygame`-[CCGLView touchesBegan:withEvent:](self=0x0000000102029c40, _cmd="touchesBegan:withEvent:", touches=0x0000000282f373c0, event=0x0000000281d62e20) at CCGLView.m:331
     frame #1: 0x00000001ca6aeaf0 UIKitCore`_UIGestureEnvironmentSortAndSendDelayedTouches + 4324
     frame #2: 0x00000001ca6a97ec UIKitCore`_UIGestureEnvironmentUpdate + 1236
     frame #3: 0x000000019d8896bc CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
     frame #4: 0x000000019d884350 CoreFoundation`__CFRunLoopDoObservers + 412
     frame #5: 0x000000019d8848f0 CoreFoundation`__CFRunLoopRun + 1264
     frame #6: 0x000000019d8840e0 CoreFoundation`CFRunLoopRunSpecific + 436
     frame #7: 0x000000019fafd584 GraphicsServices`GSEventRunModal + 100
   * frame #8: 0x00000001caa98c00 UIKitCore`UIApplicationMain + 212
     frame #9: 0x0000000100c7f8a4 mygame`main(argc=1, argv=0x000000016f2c77d8) at main.m:5
     frame #10: 0x000000019d342bb4 libdyld.dylib`start + 4

1 个答案:

答案 0 :(得分:0)

找出解决该问题的最佳方法是设置窗口的UIGestureRecognizer实例的委托:

  # in app delegate: 
  CGRect frame = [[UIScreen mainScreen] bounds];
  UIWindow *window = [[UIWindow alloc] initWithFrame:frame];
  for (UIGestureRecognizer *gestureRecognizer in [window gestureRecognizers]) {
    gestureRecognizer.delegate = self;
  }

,然后在该委托上实现以下方法:

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

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return NO;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press {
    return NO;
}