在我的情况下,主屏幕中有SearchView,还有一个侧面菜单(即SWRevealViewController
)。现在,我想在单击UISearchView
时打开键盘,而没有关闭该键盘,而是打开了侧面菜单(SWRevealViewController
)。这是过程。
现在的问题是打开侧菜单后键盘仍保持打开状态。
我应该怎么做才能在打开侧面菜单后自动关闭键盘?
现在我要尝试执行的操作:
override func viewDidLoad() {
super.viewDidLoad()
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
view.addGestureRecognizer(tap)
}
func dismissKeyboard() {
view.endEditing(true)
}
答案 0 :(得分:0)
尝试此代码,希望对您有所帮助。
class ViewController: UIViewController, SWRevealViewControllerDelegate {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var menuButton:UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
if revealViewController() != nil {
menuButton.target = revealViewController()
menuButton.action = "revealToggle:"
self.navigationController!.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
revealViewController().delegate = self
}
}
func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
textField.resignFirstResponder()
}