2016-09-19 93 views
0

我需要一些关于此问题的帮助。当用户在uisearchbar上点击时禁用键盘弹出

我想禁用键盘弹出当用户在我的应用程序中的搜索栏上点击。任何人都有如何做到这一点的想法?如果可以在应用程序中完全禁用键盘会更好。

我正在开发iOS应用程序的swift这个应用程序。

let searchController: UISearchController! 
    self.searchController = UISearchController(searchResultsController: nil) 
    self.searchController.searchResultsUpdater = self 
    self.searchController.dimsBackgroundDuringPresentation = false 
    self.searchController.searchBar.sizeToFit() 
    self.searchController.searchBar.placeholder = "Search" 

回答

0

你只需要添加UIKeyboardWillShowNotification在查看有没有加载

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardAppears), name: UIKeyboardWillShowNotification, object: nil) 

在你的类中实现keyboardAppears功能和辞职:

我在视图编程使用下面的代码添加一个搜索栏searchBard Responder。

func keyboardAppears() -> Void { 
    searchController.searchBar.resignFirstResponder() 
} 

如果要禁用键盘整个应用程序,你可以点击此链接

Close iOS Keyboard by touching anywhere using Swift

+0

非常感谢。它按我想要的那样工作。 –

+0

你可以选择以不同的方式感谢我。 –