我想通过修改键盘高度将底部约束修改为键盘出现时将视图向上。但返回给我的键盘高度是不同的。键盘高度在出现时会有所不同
当我点击模拟器中的文本框时,键盘高度为302
。当我尝试打开和关闭软件键盘时,它会在键盘出现时显示260
。这是为什么发生?
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(FriendsViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
func keyboardWillShow(notification: NSNotification) {
print("Keyboard appearing")
guard let keyboardHeight = (notification.userInfo! as NSDictionary).objectForKey(UIKeyboardFrameBeginUserInfoKey)?.CGRectValue.size.height else {
return
}
bottomConstraint.constant = keyboardHeight
print("keyboard height : \(keyboardHeight)")
self.view.layoutIfNeeded()
}
260
的高度实际上是正确的高度,因为它完美地调整了我的视角。随着302
的高度,我的观点被抵消得太多了。
我认为的布局是。 UITextField
位于顶部,其后是UITableView
。
您正在使用的设备? –
模拟iPhone 7 –
好吧,让我在这里检查你的代码,等待。 –