gpt4 book ai didi

ios - 键盘隐藏早于查看

转载 作者:行者123 更新时间:2023-11-29 05:49:47 27 4
gpt4 key购买 nike

键盘作为 subview 添加到 Collection View Controller 底部的容器中,但是当尝试隐藏它时,键盘加载似乎比增加 View 的大小更快(键盘按下后会出现一个黑色的 View )打算躲起来)。另外,当一天第一次运行该项目时,键盘不会显示,直到我按“command + K”,然后一个黑暗的 View ,因为键盘的大小出现在键盘上方和输入下方。

    @objc func handleShowKeyboard(_ notification: Notification) {
if let keyboaradSize: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue? {
let keyboardFram = keyboaradSize.cgRectValue
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {
self.view.frame.origin.y -= self.view.safeAreaInsets.bottom
self.view.frame.origin.y -= keyboardFram.height
self.view.layoutIfNeeded()

}) { (completion) in

}
}
}

@objc func handleHideKeyboard(_ notification: Notification) {
if let keyboaradSize: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue? {
let keyboardFram = keyboaradSize.cgRectValue
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {

self.view.frame.origin.y += self.view.safeAreaInsets.bottom
self.view.frame.origin.y += keyboardFram.height
self.view.layoutIfNeeded()

}) { (completion) in

}
}
}

enter image description here

最佳答案

阅读此 key

UIKeyboardAnimationDurationUserInfoKey

值并将其用作动画持续时间

<小时/>
guard let userInfo = notification.userInfo else {
return
}

guard let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double,
let curve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt else {

return
}
UIView.animate(withDuration: duration, delay: 0, options: [UIView.AnimationOptions(rawValue: curve)], animations: {
///
}) { (completed) in

}

关于ios - 键盘隐藏早于查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55795568/

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