当我单击搜索或单击取消时,键盘会隐藏.但是我还希望当我单击屏幕上的某个位置时键盘会隐藏起来.我找到了几个文本字段的教程,但我们使用的是搜索栏.
The keyboard hides when I click search or when I click on cancel. But I want also that the keyboard hides when I click somewhere on the screen. I found several tutorials for the textfield, but we are using the search bar.
谁能告诉我怎么做?
谢谢.
试试这个
在你的 .h 文件中添加 UISearchBar
in your .h file add UISearchBar
@property (strong, nonatomic) IBOutlet UISearchBar *searchBar;
在您的 .m 文件中
- (void)viewDidLoad
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
- (void) dismissKeyboard
{
// add self
[self.searchBar resignFirstResponder];
}
这篇关于触摸屏时如何隐藏键盘(搜索栏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!