gpt4 book ai didi

ios - 移动键盘时出现黑色区域

转载 作者:行者123 更新时间:2023-11-30 12:54:43 25 4
gpt4 key购买 nike

我在 View 的下半部分有一个文本字段,因此我使用下面的函数来移动我的 View 。但实际上,除了键盘顶部的黑色区域之外,一切看起来都像我想要的那样。如何处理它?任何帮助表示赞赏。 here's the screen

override func viewDidLoad() {

NotificationCenter.default.addObserver(self, selector: #selector(ViewControllerForTextfield.keyboardWillShow(_:)), name:NSNotification.Name.UIKeyboardWillShow, object: nil);
NotificationCenter.default.addObserver(self, selector: #selector(ViewControllerForTextfield.keyboardWillHide(_:)), name:NSNotification.Name.UIKeyboardWillHide, object: nil);
textField.delegate = self
super.viewDidLoad()
}


func keyboardWillShow(_ sender: Notification) {
if let keyboardSize = (sender.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
self.view.frame.origin.y -= keyboardSize.height + 100
}
}

}

func keyboardWillHide(_ sender: Notification) {
if let keyboardSize = (sender.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
self.view.frame.origin.y += keyboardSize.height
}
}
}

}

最佳答案

我认为 310 升得太高了。对于定制键盘来说,确定键盘的高度并不容易。然而,this post解释如何获取键盘的高度。

编辑:也许您还想替换从文本字段到屏幕底部的距离差?

关于ios - 移动键盘时出现黑色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40562382/

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