ios - iPhone X 键盘通知高度不同
问题描述
我最近在使用时遇到了这种奇怪的情况keyboardWillShow
,keyboardWillShow
最初调用获取键盘高度的方法(notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
返回一个 477px 的值,然后在所有其他时间它说该值现在是 535px,比它大 58px . 但是,从外观上看,键盘的外观并没有任何变化。两个键盘都启用了预测栏。
作为背景信息,需要键盘高度的目的是偏移表格视图的滚动,其中每个单元格都包含一个文本字段,并且我正在比较文本字段的位置以查看它是否在编辑开始时隐藏在键盘后面。
我在理解它的方法上是否遗漏了一些东西?
解决方案
可以帮助你吗它对我有用
NotificationCenter.default.addObserver(self, selector: #selector(CommentsVC.keyboardWillShow), name:
NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(CommentsVC.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
@objc func keyboardWillHide(_ notification: NSNotification) {
UIView.animate(withDuration: 0.3) {
self.inputContainerViewBottom.constant = 0
self.view.layoutIfNeeded()
}
}
@objc func keyboardWillShow(_ notification: NSNotification) {
print(notification)
let keyboardFrame = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue
UIView.animate(withDuration: 0.3) {
self.inputContainerViewBottom.constant = keyboardFrame!.height
self.view.layoutIfNeeded()
let flag = self.tableComments.isCellVisible(section: 0, row: 10 - 1)
if flag
{
self.scrollToBottom()
}
else
{
}
}
}
注意:inputContainerViewBottom 是底部约束的出口
推荐阅读
- python-3.x - 将唯一值列表添加到现有 DataFrame 列
- laravel - 在 Laravel 7 中配置 PhpRedis
- oauth-2.0 - OAuth 令牌,限制 API 使用
- azure-devops - 在 Azure 开发操作中使用 UniversalPackage@0 任务发布成功且没有错误,但工件源中不存在包
- python - pytest - 使用仅在运行时计算的参数对测试进行参数化
- erlang - Erlang:异常错误:读取文本文件时右侧值{error,enoent}不匹配
- swift - Swift Google Maps 未进入安全区域
- node.js - 带有 npm 模块的“语法错误:无法在模块外使用 import 语句”
- javascript - 如何获取输入/选择信息,然后从那里打印数据库信息。这可能吗?
- networking - 从 WLAN 中继器到基站路由器的网络打印机反射