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);
}
You must be logged in to post a comment.
第一次来,感谢博主的分享,以后会常来看博主的。
谢谢博主的分享,以后会常来的。对了,有需要空间、服务器的可以了解下恒创的,俗话说货比三家。
学到了,感谢博主的分享,以后会常来的。