iOS 点击空白处收回键盘的几个简单代码
//收回键盘1
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[((UIView*)obj) resignFirstResponder];
}];
}
//收回键盘2
- (void)resignKeyBoardInView:(UIView *)view
{
for (UIView *v in view.subviews)
{
if ([v.subviews count] > 0)
{
[self resignKeyBoardInView:v];
}
if ([v isKindOfClass:[UITextView class]] || [v isKindOfClass:[UITextField class]]) {
[v resignFirstResponder];
}
}
}
//收回键盘3--
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[UITextField class]])
[view resignFirstResponder];
}
}
//收回键盘4---适用scrollview
//前提:view继承UIContorl,连线Touch Down
//Touch Down--Action
- (IBAction)backgroundTap:(id)sender
{
[phoneNumberTextFiled resignFirstResponder];//通知文本失去第一响应者状态 键盘收回
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。