给UIImageView添加点击事件

- (void)viewDidLoad

{

[super viewDidLoad];

UIImage * image = [UIImage imageNamed:@"alien.png"];

CGSize size = image.size;

UIImageView *imgview = [[UIImageView alloc]initWithFrame:(CGRect){{100,100},size}];

imgview.image = image; [self.view addSubview:imgview];

imgview.userInteractionEnabled = YES;

UITapGestureRecognizer *singtap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickimg:)];

[imgview addGestureRecognizer:singtap];

}

-(void)clickimg:(id)sender

{

UIImageView *v = (UIImageView*)((UITapGestureRecognizer *)[sender view]);

NSLog(@"fafasf");

}

 

 

posted @ 2012-05-04 23:22  高笑228  阅读(229)  评论(0编辑  收藏  举报