gpt4 book ai didi

ios - 如何获得实际键盘高度(键盘高度减去安全区域插入)

转载 作者:行者123 更新时间:2023-11-28 05:44:20 30 4
gpt4 key购买 nike

我尝试获取键盘的高度,以便在键盘出现时更新表格 contentInsets;但是来自 UIResponder.keyboardWillShowNotification 的通知显示了具有安全区域高度的框架。有没有办法获得实际的键盘框架?

键盘高度的代码:

if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
let keyboardRectangle = keyboardFrame.cgRectValue
let keyboardHeight = keyboardRectangle.height

print("show: \(keyboardHeight)")
tableView.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 18 + keyboardHeight, right: 0)
tableView.contentInset = UIEdgeInsets(top: 8, left: 0, bottom: 18 + keyboardHeight, right: 0)
}

但这给出了以下键盘的高度: https://imgur.com/m0HR088

我想要的: https://imgur.com/Lp6vHOm

最佳答案

First you have to get Safe Area bottom height and then exclude it from keyboard total height. In this way you will get only keyboard height without bottom safe area.

伪代码:

let keyboardHeight = your keyboard height - bottomPadding

if #available(iOS 11.0, *) {
let window = UIApplication.shared.keyWindow
let bottomPadding = window?.safeAreaInsets.bottom
}

希望对你有所帮助。

关于ios - 如何获得实际键盘高度(键盘高度减去安全区域插入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55450602/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com