我目前在我的桌面视图中有此设置。:
tableView.keyboardDismissMode = .interactive
我有一个通知观察员设置如下:
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
当键盘最终被拖出屏幕时,会调用我的keyboardWillHide
方法。有没有办法检测键盘是如何被解雇的?调用keyBoardWillHide
时,我需要知道是否因为按下了返回键,或者用户是否拖动它以便我可以调整动画。这有什么回调吗?
答案 0 :(得分:0)
SetUp变量如:
var checker : Bool = false
设置keyBoardWillHide的通知:
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: .UIKeyboardWillHide, object: nil)
}
按Return
按键返回键盘:
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
checker = true
textField.resignFirstResponder()
return true
}
键盘将隐藏选择器调用:
func keyboardWillHide (notif: Notification)
{
if (checker == true)
{
print ("Return key pressed")
}
else
{
print ("Table dragged down")
}
checker = false
}
希望这有帮助。