我想更改 iOS 中小数点键盘的高度。我得到默认键盘高度和小数点键盘的黑白高度差。
func resizeKeyboard(note: NSNotification){
let userInfo = note.userInfo!
let duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as! Double
let curve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as! UInt
var frameEnd = self.view .convert(((userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue), from: nil)
if note.name == NSNotification.Name.UIKeyboardWillShow{
Keyboard appears
desiredHeight = 260
}else if note.name == NSNotification.Name.UIKeyboardWillHide{
Keyboard hides
desiredHeight = 260
}
self.heightConstraint.constant = desiredHeight
self.view .setNeedsLayout()
UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(rawValue: curve), animations: {
self.view .setNeedsLayout()
}, completion: nil)
}
最佳答案
您无法更改系统键盘的高度,如 documentation说,这并不总是相同的:
You should always use the information in these notifications as opposed to assuming the keyboard is a particular size or in a particular location. The size of the keyboard is not guaranteed to be the same from one input method to another and may also change between different releases of iOS.
这意味着您的代码需要查看 UIKeyboardFrameEndUserInfoKey
来确定实际的键盘高度,并调整/滚动 UI 的其余部分以适应该高度。
关于ios - iOS 有没有办法调整键盘高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48352946/