clickx 作为一个方法被调用,表示当你点击图片的时候出发这个方法,这个方法可以自己随便写比如abc,clicky
- (IBAction)test:(id)sender {
UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
imageView.image=[UIImage imageNamed:@"22.png"];
imageView.userInteractionEnabled = YES;
[imageView setTag:2];//为了带个参数过去,设置值大一些
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickx:)];
[imageView addGestureRecognizer:singleTap];
//[singleTap release];
[self.view addSubview:imageView];
}
UITapGestureRecognizer 带过来的参数 gesture 将索引值tag给传递过来
- (IBAction)clickx:(id)sender,UITapGestureRecognizer *gesture{
UIView *temView = [gesture view];
NSInteger temIndex = temView.tag;
NSLog(@"aaaa%d",temIndex);
}