我在从 imageview 获取标签号时遇到了麻烦。我将 UIGestureRecognizer 添加到滚动视图中的每个图像视图中,并尝试从触摸视图中获取标签号。在我触摸图像后,什么都没有发生。我的代码错了吗?请帮我。
// to add images
for (int i = 0; i < app.arrPhotoList.count; i++) {
UIImageView *subImg = [[UIImageView alloc]initWithFrame:frame];
subImg.contentMode = UIViewContentModeScaleAspectFit;
subImg.layer.borderColor = [UIColor blackColor].CGColor;
subImg.layer.borderWidth = 2.0f;
subImg.tag = i;
subImg.userInteractionEnabled = YES;
UIGestureRecognizer *singleTab = [[UIGestureRecognizer alloc]initWithTarget:self action:@selector(imageTag:)];
[subImg addGestureRecognizer:singleTab];
/////// add img to array of imageviews/////////////
NSString *imgName = [[app.arrPhotoList objectAtIndex:i]stringByAppendingString:@"_thumb.jpg"];
subImg.image = [UIImage imageWithContentsOfFile:imgName];
[scrImgView addSubview:subImg];
}
-(void) imageTag:(UIGestureRecognizer *)sender{
NSLog(@"you selected tag number is : %d",sender.view.tag);
}