//interface builder中没有提供对点击组件ImageView、Label的响应,在程序运行初期添加gesture recognizer可以实现对相应点击事件的响应
- (void)viewDidLoad
{
[super viewDidLoad];
//在viewDidLoad中增家gesture recognizer
UITapGestureRecognizer *tapRecognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickEventOnImage:)];
self.imageview.userInteractionEnabled=YES;
[self.imageview addGestureRecognizer:tapRecognizer];
UITapGestureRecognizer *tapRecognizer2=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickEventOntext:)];
self.text.userInteractionEnabled=YES;
[self.text addGestureRecognizer:tapRecognizer2];
}
-(void) ClickEventOnImage:(id)sender
{
NSLog(@"imageview点击事件ok");
}
-(void) ClickEventOntext:(id)sender
{
NSLog(@"label点击事件ok");
}
- (void)viewDidLoad
{
[super viewDidLoad];
//在viewDidLoad中增家gesture recognizer
UITapGestureRecognizer *tapRecognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickEventOnImage:)];
self.imageview.userInteractionEnabled=YES;
[self.imageview addGestureRecognizer:tapRecognizer];
UITapGestureRecognizer *tapRecognizer2=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickEventOntext:)];
self.text.userInteractionEnabled=YES;
[self.text addGestureRecognizer:tapRecognizer2];
}
-(void) ClickEventOnImage:(id)sender
{
NSLog(@"imageview点击事件ok");
}
-(void) ClickEventOntext:(id)sender
{
NSLog(@"label点击事件ok");
}