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); } |
时间: 2024-09-27 10:36:46