1

我使用标签值创建了 5 个具有不同图像的图像视图。现在我想在 touches Began 方法中确定当前触摸的图像视图。

请任何人帮助指导。

4

2 回答 2

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.

希望这可以帮助!

于 2012-08-30T07:04:32.587 回答
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
      }
    }
  }
}
于 2012-08-30T07:14:00.333 回答