问题描述
我有 bottomView(图像中带有黑色边框的那个)它的底部锚点对底部视图 safeAreaLayoutGuide 有约束,但是当键盘显示时,bottomView 变成了键盘的工具栏。
这里的一切都在 iOS 14 中按预期工作(如图像 1 和 3)但是在 iOS 13 中运行项目时,我发现 safeAreaInsets 在键盘关闭(红色空间增加其高度,如图像 2)
我尝试了一些提到 here 的解决方案,但没有帮助 任何人都可以为此提出解决方案吗?
@objc func adjustForKeyboard(notification: Notification) {
guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
let keyboardScreenEndFrame = keyboardValue.cgRectValue
let keyboardViewEndFrame = view.convert(keyboardScreenEndFrame,from: view.window)
if notification.name == UIResponder.keyboardWillHideNotification {
bottomViewConstraint?.constant = 0
NotesText.contentInset = .zero
} else {
bottomViewConstraint?.constant = -(keyboardViewEndFrame.height - self.view.safeAreaInsets.bottom)
NotesText.contentInset = UIEdgeInsets(top: 0,left: 0,bottom: -(keyboardViewEndFrame.height + bottomViewConstraint!.constant),right: 0)
//FIXME:- force unwrap
}
NotesText.scrollIndicatorInsets = NotesText.contentInset
let selectedRange = NotesText.selectedRange
NotesText.scrollRangetoVisible(selectedRange)
}
并在 viewDidAppear 中调用此函数也尝试在 viewSafeAreaInsetsDidChange 中调用它但行为没有改变
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
addKeyboardNotification()
// Show keyboard by default
NotesText.becomeFirstResponder()
}
fileprivate func addKeyboardNotification() {
let notificationCenter = NotificationCenter.default
notificationCenter.addobserver(self,selector: #selector(adjustForKeyboard),name: UIResponder.keyboardWillHideNotification,object: nil)
notificationCenter.addobserver(self,name: UIResponder.keyboardWillChangeFrameNotification,object: nil)
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)