iOS 8 - 如何隐藏键盘上方的建议列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24140116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:46:30  来源:igfitidea点击:

iOS 8 - How to hide suggestion list above keyboard?

iosswiftios8xcode6

提问by Khawar

Is there any way to hide suggestions list above keyboard? I couldn't find any solution in documentation.

有没有办法隐藏键盘上方的建议列表?我在文档中找不到任何解决方案。

回答by Mick MacCallum

Yes there is. You have to disable autocorrection on the text field/text/any other class that conforms to the UITextInputTraits protocol,which can be done through the autocorrectionTypeproperty.

就在这里。您必须在符合UITextInputTraits 协议的文本字段/文本/任何其他类上禁用自动更正,这可以通过autocorrectionType属性完成。

textField.autocorrectionType = .no

Additionally, if you're interested, the following are the only UIKeyboardTypesthat don't have suggestions by default.

此外,如果您有兴趣,以下是唯一 默认没有建议的UIKeyboardType

  • DecimalPad
  • NumberPad
  • PhonePad
  • 十进制数
  • 数字键盘
  • 手机平板

回答by Kiran P Nair

In swift 2 hide Suggestion using this code :

在 swift 2 中使用以下代码隐藏建议:

textField.autocorrectionType = UITextAutocorrectionType.No

Swift 3:0

斯威夫特 3:0

textfield.autocorrectionType = .no

To hide bar (Predictive bar) use this code :

要隐藏栏(预测栏),请使用以下代码:

if #available(iOS 9.0, *) {
        var item = textFeild.inputAssistantItem
        item.leadingBarButtonGroups = [];
        item.trailingBarButtonGroups = [];
    }

For Disable copy past , use this function

对于禁用复制过去,请使用此功能

override func selectionRectsForRange(range: UITextRange) -> [AnyObject] {
    return []
}

override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
    let menu = UIMenuController.sharedMenuController()
    menu.menuVisible = false
    return false
}

Swift 3

斯威夫特 3

override func selectionRects(for range: UITextRange) -> [Any] {
    return []
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    let menu = UIMenuController.shared
    menu.isMenuVisible = false
    return false


}

回答by auspicious99

(Edit in Oct 2019: still true for Xcode 11.1)

(2019 年 10 月编辑:Xcode 11.1 仍然如此)



In more recent versions of Xcode storyboards, you can also set the keyboard traits in the storyboard (right panel, the attributes inspector, then look for Text Input Traits and select the traits you want, at least in Xcode 9). In particular, select "No" for the Correction trait, as shown in the example below. Interestingly, this is for content type Username, and the Default selection for the Correction trait was to turn on Correction, unlike a content type like Password, for example. Example of setting this in the storyboard

在较新版本的 Xcode 故事板中,您还可以在故事板中设置键盘特征(右侧面板,属性检查器,然后查找文本输入特征并选择您想要的特征,至少在 Xcode 9 中)。特别是,为 Correction trait 选择“No”,如下例所示。有趣的是,这是针对内容类型用户名的,例如,与密码等内容类型不同,更正特征的默认选择是打开更正。 在故事板中设置它的示例

回答by Aaron

For anybody who landed here that is attempting to disable/hide the iOS 11 password autofill bar, here is one solution.

对于登陆这里试图禁用/隐藏 iOS 11 密码自动填充栏的任何人,这里是一种解决方案