Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内容顶部的IOS键盘建议栏_Ios_Swift_Xcode_User Interface - Fatal编程技术网

内容顶部的IOS键盘建议栏

内容顶部的IOS键盘建议栏,ios,swift,xcode,user-interface,Ios,Swift,Xcode,User Interface,对于我的RMIT课程,我正在阅读《应用程序开发与Swift》一书,现在正在研究滚动视图 我实现了书中告诉我的代码,使滚动视图移动到键盘之外,但它没有注意到键盘顶部的建议栏,因此这肯定不理想,因为它是我试图输入文本的电话号码字段 我使用的代码如下 func registerForKeyboardNotifications() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasS

对于我的RMIT课程,我正在阅读《应用程序开发与Swift》一书,现在正在研究滚动视图

我实现了书中告诉我的代码,使滚动视图移动到键盘之外,但它没有注意到键盘顶部的建议栏,因此这肯定不理想,因为它是我试图输入文本的电话号码字段

我使用的代码如下

    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