我只是注意到我的键盘高度标识代码不再与ios11一起使用。
对于ios10设备,我使用此逻辑来检测,如果键盘将隐藏特定的输入字段(在我的情况下,文本字段)。如果这样,将在最后一个活动的文本字段下显示键盘以启用用户的输入。
在iOS 11的情况下,键盘的识别高度不起作用。
键盘的辅助类示例Willappear Logic 这只是一个示例键盘WillShow所做的 ->仅检查视图是否需要在键盘上方移动,如果键盘将隐藏Textfield。
我做了一些debuggin,发现下面的代码线在iOS 10和iOS 11之间的工作方式有所不同:
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
ios10调试器输出
键盘键cgRect(origin =(x = 0,y = 568),size =(width = 320,高度= 216))
ios11调试器输出
键盘cgrect(origin =(x = 0,y = 568),size =(width = 320,高度= 0))
您可以看到完整的代码 - 直到iOS 10.3
func keyboardWillShow(notification: NSNotification, view: UIView, activeTextField: UITextField?, scrollView: UIScrollView?) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if view.frame.origin.y == 0{
var aRect : CGRect = (view.viewWithTag(2)?.frame)!
aRect.size.height -= keyboardSize.height
if let activeField = activeTextField {
let tempPoint = CGPoint(x: activeField.frame.origin.x, y: activeField.frame.origin.y + 20)
if (aRect.size.height < tempPoint.y){
view.frame.origin.y -= keyboardSize.height
if let scrollView = scrollView {
let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.size.height)
scrollView.setContentOffset(bottomOffset, animated: true)
}
}
}
}
}
}
更新2017/09/20
我现在尝试了几次。有时它也向我显示了ios11的键盘高度值 - 现在我完全困惑.....
使用UIKeyboardFrameEndUserInfoKey
代替UIKeyboardFrameBeginUserInfoKey