2013-03-05 63 views
0

我的问题如下:TouchesEnded未被调用第二次

我在标准视图控制器中显示带附件的消息视图。当用户按下并保持附件图标时,它会在屏幕上显示图像,当用户放开图像时消失。这有助于在用户查看图像时检测屏幕截图。

我使用长按手势识别器来检测触摸,然后触摸已着手或触摸取消检测触摸的释放。

当用户使用第二个手指按下屏幕时会出现我的问题,因为未报告第二次触摸的发布。代码如下,该方法被调用的顺序:

  1. 首先长按 - > attachmentLongPressed叫
  2. 第二长按 - > attachmentLongPressed叫
  3. 发布第一根指头 - > touchesEnded叫
  4. 松开第二根手指 - >叫什么

    -(void)attachmentImageLongPressed:(UIImageView *)sender{ 
    
        if(!self.isAttachmentOpen){ 
    
         [self setAttachmentOpen:YES]; 
    
         // Show image... 
    
        } 
    } 
    
    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 
    
        [self setAttachmentOpen:NO]; 
    
        // Remove image from view 
    
    } 
    
    -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
    { 
        if(self.isAttachmentOpen){ 
    
         [self screenshotDetected]; 
    
        } 
    } 
    

结果是图像视图留在屏幕上,无法解除它。任何人有任何建议?

回答

0

我认为它应该被称为touchesEnded当释放第二根手指。您可以记录所有回调中的所有触摸,找出正在调用哪种方法,

但是,长按手势可能会延迟触摸结束事件,因此请尝试将delaysTouchesEnded设置为FALSE。

gestureLongPressed.delaysTouchesEnded = FALSE

+0

touches ended不会被第二次调用,那就是问题所在。我记录回调,这是我知道这一点。禁用它没有任何意义,整个想法是,我需要触摸结束被称为将图像从屏幕上移开... – Alan 2013-03-06 07:16:17

相关问题