gpt4 book ai didi

ios - KeyboardWillHide 在 KeyboardWillShow 仍在动画时被调用

转载 作者:搜寻专家 更新时间:2023-11-01 07:22:15 26 4
gpt4 key购买 nike

目前我有一个 View 在键盘显示或隐藏时使用键盘进行动画处理。我添加了一个手势识别器,这样当用户点击键盘时它就会消失。

我遇到的问题是,如果用户在键盘出现时点击以降低键盘,键盘就会消失,我的 View 不会降低。我实际上注意到,无论出于何种原因,视野都变得更高了。

这是我的键盘监听器方法:

func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
if let tabBarController = tabBarController {
responseNode.frame.origin.y -= keyboardSize.height-tabBarController.tabBar.frame.height
tableNode.view.contentInset.bottom += keyboardSize.height-tabBarController.tabBar.frame.height
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
if let tabBarController = tabBarController {
responseNode.frame.origin.y += keyboardSize.height-tabBarController.tabBar.frame.height
tableNode.view.contentInset.bottom -= keyboardSize.height-tabBarController.tabBar.frame.height
}
}
}

这是我隐藏键盘的方法:

extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
}

func dismissKeyboard() {
view.endEditing(true)
}
}

如有任何帮助,我们将不胜感激!

最佳答案

试试这个

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}

func textFieldShouldReturn(textField: UITextField) -> Bool {

text.resignFirstResponder()

return true

}

关于ios - KeyboardWillHide 在 KeyboardWillShow 仍在动画时被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38214455/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com