Gav*_*vin 3 nsnotifications ios swift
我试图通过将底部约束修改为键盘高度来显示键盘时的视图。但是返回给我的键盘高度是变化的。
当我点击模拟器中的文本字段时,键盘高度为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()
}
Run Code Online (Sandbox Code Playgroud)
的高度260实际上是正确的高度,因为它完美地调整了我的视野。随着302我的观点高度偏移了太多。
我的观点的布局是。UITextField在顶部,然后在其UITableView下方。
| 归档时间: |
|
| 查看次数: |
1265 次 |
| 最近记录: |