ios 增加对点击图片的响应

interface builder中没有提供对点击组件ImageView、Label的响应,在程序运行初期添加gesture recognizer可以实现对相应点击事件的响应,例如实现点击背景图片关闭键盘操作

1、在viewDidLoad中增家gesture recognizer

UITapGestureRecognizer*tapRecognizer=[[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(ClickEventOnImage:)];

    self.imageview.userInteractionEnabled=YES;

    [self.imageviewaddGestureRecognizer:tapRecognizer];

2、在响应函数中对界面中所有的Text Field发送resignFirstResponser消息

-(void) ClickEventOnImage:(id)sender

{

    [self.nameresignFirstResponder];

    [self.passwordresignFirstResponder];

}

你可能感兴趣的:(ios)