gpt4 book ai didi

ios - 折叠键盘、工具栏

转载 作者:行者123 更新时间:2023-11-28 15:31:25 29 4
gpt4 key购买 nike

collapsed keyboard

如何检查键盘何时完全显示以及何时像这样折叠?也许我可以检查它的高度?

我暂时检查了 notification 中的 userInfo,但没有发现对解决我的问题有用。

最佳答案

只需订阅通知:

NotificationCenter.default.addObserver(self, selector: 
#selector(self.adjustForKeyboard), name:
NSNotification.Name.UIKeyboardDidShow, object: nil)

NotificationCenter.default.addObserver(self, selector:
#selector(self.adjustForKeyboard), name:
NSNotification.Name.UIKeyboardDidHide, object: nil)

然后贴近下一个方法

func adjustForKeyboard(notification: NSNotification) {
let userInfo = notification.userInfo!

if let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardViewEndFrame = delegate.getView().convert(keyboardScreenEndFrame, from: delegate.getView().window)

var customInset = UIEdgeInsets.zero
if notification.name == NSNotification.Name.UIKeyboardDidHide {
customInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
} else {
customInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardViewEndFrame.height, right: 0)
}

scrollView.contentInset = customInset
scrollView.scrollIndicatorInsets = customInset
}
}

当你离开这个 VC 时不要忘记移除观察者

NotificationCenter.default.removeObserver(self)

关于ios - 折叠键盘、工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44702800/

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