转
方法一:
//1, 关闭键盘
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
想必大家都遇到过一个view上好多输入框,为了关闭弹出的软键盘要遍历然后调用resignFirstResponder的吧?今天竟然发现一个关键这个view上可能 打开的键盘很简单:[self.view endEditing:YES];
直接ok了。
方法二:
//2, 关闭键盘
[[selffindFirstResponderBeneathView:self]resignFirstResponder];
[[selffindFirstResponderBeneathView:self]becomeFirstResponder];//打开键盘
- (UIView*)findFirstResponderBeneathView:(UIView*)view
{
// Search recursively for first responder
for(UIView*childViewinview.subviews) {
if( [childViewrespondsToSelector:@selector(isFirstResponder)] && [childViewisFirstResponder] )
returnchildView;
UIView*result = [selffindFirstResponderBeneathView:childView];
if( result )
returnresult;
}
returnnil;
}