内容顶部的IOS键盘建议栏
对于我的RMIT课程,我正在阅读《应用程序开发与Swift》一书,现在正在研究滚动视图 我实现了书中告诉我的代码,使滚动视图移动到键盘之外,但它没有注意到键盘顶部的建议栏,因此这肯定不理想,因为它是我试图输入文本的电话号码字段 我使用的代码如下内容顶部的IOS键盘建议栏,ios,swift,xcode,user-interface,Ios,Swift,Xcode,User Interface,对于我的RMIT课程,我正在阅读《应用程序开发与Swift》一书,现在正在研究滚动视图 我实现了书中告诉我的代码,使滚动视图移动到键盘之外,但它没有注意到键盘顶部的建议栏,因此这肯定不理想,因为它是我试图输入文本的电话号码字段 我使用的代码如下 func registerForKeyboardNotifications() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasS
func registerForKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(_:)),name: .UIKeyboardDidShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(_:)), name: .UIKeyboardWillHide, object: nil)
}
@objc func keyboardWasShown(_ notification: NSNotification) {
guard let info = notification.userInfo,
let keyboardFrameValue = info[UIKeyboardFrameBeginUserInfoKey] as? NSValue
else {return}
let keyboardFrame = keyboardFrameValue.cgRectValue
let keyboardSize = keyboardFrame.size
let contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
@objc func keyboardWillBeHidden(_ notification: NSNotification) {
let contentInsets = UIEdgeInsets.zero
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
我想知道这段代码是否是在建议栏出现之前编写的,是否有一种新的方法包括建议栏。用
UIKeyboardFrameEndUserInfoKey
替换此键UIKeyboardFrameEndUserInfoKey