[英]black area when moving keyboard
我在視圖的下半部分有一個文本字段,因此我正在使用下面的函數移動我的視圖。 但是實際上除了鍵盤頂部的黑色區域外,其他所有東西看起來都像我想要的那樣。如何處理呢? 這是屏幕
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漲幅太大。 對於自定義鍵盤,確定鍵盤的高度並不容易。 但是, 這篇文章解釋了如何獲得鍵盤的高度。
編輯:也許您還想替換從文本字段到屏幕底部的距離的差異?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.