UItextView在textview外部轻击键盘

inf*_*eqd 3 uitextview uiview uikeyboard ios

我有一个custom UIView来自a UIViewController.该视图控制器可以呈现几个这样的视图中的一个.其中一个观点有一个UITextView.当一个人开始输入文字时UITextView,会显示键盘.但是,每当用户点击textview之外的任何地方时,我想解除键盘.由于UIViewsUIViewController基于某些条件可以呈现多个,我封装了UITextView委托方法等custom UIView,我这样做是使用Notifications from the custom UIViewlike

- (void)configureView
{ 
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver:self selector:@selector(keyboardWillShow:) name:
 UIKeyboardWillShowNotification object:nil];

[nc addObserver:self selector:@selector(keyboardWillHide:) name:
 UIKeyboardWillHideNotification object:nil];

self.tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                           action:@selector(didTapAnywhere:)];
}

-(void) keyboardWillShow:(NSNotification *) note {
[self addGestureRecognizer:self.tapRecognizer];
}

-(void) keyboardWillHide:(NSNotification *) note
{
[self removeGestureRecognizer:self.tapRecognizer];
}

-(void)didTapAnywhere: (UITapGestureRecognizer*) recognizer {    
[self.detailsTextView resignFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)

但是,当调用didTapAnywhere时,即使resignfirstresponder绑定,键盘也不会被解雇.仅供参考,代表UITextViewcustom UIView.

帮助如何做到这一点

BBo*_*Bog 5

尝试

[self.view endEditing:YES];

而不是辞职第一响应者.这应该可以解决问题.有什么奇怪的是为什么标准方法不起作用......