我正在开发一个应用程序,将图像添加到NSMutableArray
并将它们显示在图像视图中。在所选或点击的图像的NSMutableArray中获取索引
我的问题是,我不知道如何获得我的应用程序中选定或点击图像的索引。
FrontsCards=[[NSMutableArray alloc]initWithObjects:@"cloub1.png",@"cloub2.png",@"cloub3.png",@"cloub4.png", nil];
for(int m=0; m< [FrontsCards count];m++)
{
NSString *imageName=[FrontsCards objectAtIndex:m];
NSString *fullImageName=[NSString stringWithFormat:@"%@",imageName];
int padding=25;
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[ImgView setImage:[UIImage imageNamed:fullImageName]];
[ImgView setContentMode:UIViewContentModeScaleAspectFill];
[scrollView addSubview:ImgView];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
[self.ImgView addGestureRecognizer:doubleTap];
self.ImgView.userInteractionEnabled=YES;
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[FrontsCards count], scrollView.frame.size.height);
[scrollView setContentSize:scrollViewSize];
[self.view addSubview:scrollView];
我应该怎样做我的水龙头手势识别器来获取图像的索引?
- (void)doubleTapImgView:(UITapGestureRecognizer *)gesture
{
NSLog(@"double-tap");
}
在这种情况下,gesture.view将给ImageView并在FrontCards数组中包含UIImages。所以它不会给你指数。只是想让你知道:) – Ushan87 2013-05-14 09:51:35
@ Ushan87谢谢!更新我的代码,也许这可以现在工作。我使用accessibiltyIdentifier :) – Joshua 2013-05-14 10:30:39
@joshua这段代码适合我。非常感谢你。 – Jitendra 2013-05-20 10:19:57