【问题标题】:Continuous Touch detection in imageView using Touch event..?使用触摸事件在imageView中进行连续触摸检测..?
【发布时间】:2012-07-06 07:33:42
【问题描述】:

我有一个调用另一个视图的方法。我想在图像连续一段时间后调用此方法。

这种方法在 UIButton = touchDown(),touchup() 中找到。

触摸事件中是否有任何方法可以在图像视图中找到连续触摸。

请帮帮我。

提前感谢

【问题讨论】:

  • 使用手势识别器

标签: iphone cocoa-touch uiimageview


【解决方案1】:

您可以将这些事件用于 UIIMAGEVIEW:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 

【讨论】:

  • 谢谢,但是这种方法只能在图像视图中找到触摸。我正在尝试检测图像视图上的连续触摸。就像在 UIButton touchdown() 方法中一样。
  • touchesBegan 和 touchesEnd 只是事件
【解决方案2】:

您可以使用点击手势,您可以看到我在this 线程中写的答案。在此您可以设置需要触发事件的点击次数。希望这对您有所帮助。

【讨论】:

    【解决方案3】:

    假设您想计算触摸次数(连续双击)

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    
    int index =[touch view].tag;
    
    if (touch.tapCount == number && index == imageTag) {
    
    }
    
    }
    

    tapCount 将是在很短的时间间隔(双击)的持续时间内的点击计数。如果您想要观看的点击次数延迟较长(例如 5 次点击),您将无法使用它。或者,您可以记住您的 imageview 的触摸,例如:

     - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
          UITouch *touch = [[event allTouches] anyObject];
          int index =[touch view].tag;
    
          if(index == imagetag){
             if([tempMutableArray count] < definiteTime){
                [tempMutableArray addObject:@"any"]
               }else{ 
                [tempMutablArray removeAllObjects]; 
                //you can call the method now
                }
          }
    }
    

    【讨论】:

    • 这里的“tempMutableArray”是什么..??
    • 它是 NSMutableArray 的一个实例,它应该在头文件中。代码只是为了给你一个想法,手势识别器也是一个选项
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多