从许多图像视图中检测精确的图像视图

时间:2012-08-30 06:56:52

标签: iphone

我使用标记值创建了5个不同图像的图像视图。现在我想确定当前触摸的图像视图触摸开始方法。

请任何人帮助指导。

2 个答案:

答案 0 :(得分:1)

试试这个: -

触摸开始方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[touches allTouches]anyObject]; // Picks up the touch
NSLog(@"touched view%@",[touch view]);
UIView *view=[touch view];//here you can find the view which is touched and after that you can compare it with your image views like
if(view==(UIImageView *)[self.view viewWithTag:1])
{
//first image view touched
}
}
//you can proceed in this way.

希望这有帮助!

答案 1 :(得分:0)

试试这个:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
  UITouch *touch = [[touches allTouches]anyObject]; // Picks up the touch
  UIImageView *view=(UIImageView *)[touch view];//here you can find the view which is touched and after that you can compare it with your image views like
 if(view){

      if([view tag] == 0)
      {
          //UIImageView with tag 0 touched
      }
      else if([view tag] == 1)
      {
          //UIImageView with tag 1 touched
      }
      else if([view tag] == 2)
      {
          //UIImageView with tag 2 touched
      }
      else if([view tag] == 3)
      {
          //UIImageView with tag 3 touched
      }
      else if([view tag] == 4)
      {
          //UIImageView with tag 4 touched
      }
    }
  }
}