2012-07-06 59 views
1

我有一个调用另一个视图的方法。我想在图像持续一定时间后调用这个方法。使用触摸事件在imageView中进行连续触摸检测..?

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

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

请帮我。

在此先感谢

+0

使用手势识别器 – 2012-07-06 08:33:53

回答

0

您可以使用这些事件的UIImageView:

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

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

谢谢,但这种方法只在图像视图中找到触摸。我试图检测图像视图上的连续触摸。就像在UIButton touchdown()方法中一样。 – 2012-07-06 08:42:57

+0

touchesBegan和touchesEnd是只有事件 – 2012-07-06 08:55:53

0

假设你要计算的触摸(连喜欢双击)

- (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 
      } 
     } 
} 
+0

什么是“tempMutableArray”在这里.. ?? – 2012-07-06 08:52:21

+0

它应该在头文件中的一个NSMutableArray的实例。代码只是为了给你一个想法,手势识别器也是一个选项 – janusbalatbat 2012-07-06 09:00:20

0

您可以使用点击手势,你可以看到我在写this这thread.In的答案,你可以设置哪些需要抽头数发射事件。希望这可以帮助你。