在UITextView上以编程方式禁用iOS8 Quicktype键盘

rih*_*ihe 68 xcode objective-c ios ios8

我正在尝试更新iOS8的应用程序,它有一个聊天界面,但新的Quicktype键盘隐藏了文本视图,因此我想以编程方式或在界面构建器中关闭它.

是否可能以某种方式或仅用户可以在设备设置中将其关闭?

我知道有一个问题/答案用a来解决这个问题UITextfield,但我需要用a来解决这个问题UITextView.

mih*_*hai 124

您可以为UITextView禁用键盘建议/自动完成/ QuickType,它可以阻止像4S这样的较小屏幕上的文本,如本例所示

使用以下行:

myTextView.autocorrectionType = UITextAutocorrectionTypeNo;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述

而且,如果您只想在特定屏幕上执行此操作,例如定位4S

if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
    if (screenHeight == 568) {
        // iphone 5 screen
    }
    else if (screenHeight < 568) {
       // smaller than iphone 5 screen thus 4s
    }
}
Run Code Online (Sandbox Code Playgroud)

  • UITextAutocorrectionTypeNo在iPhone 6中不起作用-iOS 8.1 (2认同)
  • @iGW当我在UITextView或UITextField已经是第一个响应者之后这样做时,它对我来说也不起作用.尝试在此之前设置它,或者触发resign和becomeFirstResponder(前者显然是"正确"和更合适的方式. (2认同)
  • 仅供参考,对于Swift,代码为textField.autocorrectionType = .No (2认同)

Nik*_*kin 52

为了完整起见,我想补充一点,你也可以这样做Interface Builder.

要禁用设置为的UITextFieldUITextView- 中的键盘建议.Attributes InspectorCorrectionNo

在此输入图像描述


DZe*_*Bot 7

我用以下方法创建了一个UITextView类别类:

- (void)disableQuickTypeBar:(BOOL)disable
{
    self.autocorrectionType = disable ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;

    if (self.isFirstResponder) {
        [self resignFirstResponder];
        [self becomeFirstResponder];
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望有一个更清洁的方法.此外,它假设自动校正模式Default,对于每个文本视图可能并非总是如此.