我正在尝试使用一组可点击的 UIImageView 创建一个滚动视图。我的目标是,当单击 ImageView 时,它会返回它在数组中占据的位置。问题是我不知道如何“抓住”职位的号码。我怎么做?
到目前为止,我有:
- (IBAction)respondToTapGesture:(UITapGestureRecognizer *)recognizer {
NSLog(@"%@",)//here is where i want to return the element's position.
}
-(void) preenchemenu {
[menu setContentSize:CGSizeMake(400, 91)];
int x=0;
imagensmenu=[NSArray arrayWithObjects:[UIImage imageNamed:@"teste2.tiff"],[UIImage imageNamed:@"teste2.tiff"], nil];
for (int i = 0; i <3; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x,0 , 90, 91)];
x=x+90;
imageView.image = [imagensmenu objectAtIndex:i];
imageView.tag = 1000+ i;
imageView.userInteractionEnabled = YES;
imageView.multipleTouchEnabled = YES;
UITapGestureRecognizer *tapRecognizermenu = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondToTapGesture:)];
tapRecognizermenu.numberOfTapsRequired = 1;
[imageView addGestureRecognizer:tapRecognizermenu];
[menu addSubview:imageView];
}
}