Disable iOS8 Quicktype Keyboard programmatically on UITextView

IosObjective CXcodeIos8

Ios Problem Overview


I'm trying to update an app for iOS8, which has a chat interface, but the new Quicktype keyboard hides the text view, so I would like to turn it off programmatically or in interface builder.

Is it possible somehow or only the users can turn it off in the device settings?

I know there is a question/answer which solves this problem with a UITextfield, but I need to do it with a UITextView.

Ios Solutions


Solution 1 - Ios

You may disable the keyboard suggestions / autocomplete / QuickType for a UITextView which can block the text on smaller screens like the 4S as shown in this example

with the following line:

myTextView.autocorrectionType = UITextAutocorrectionTypeNo;

enter image description here enter image description here

And further if youd like to do this only on a specific screen such as targeting the 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
    }
}

Solution 2 - Ios

For completeness sake I would like to add that you can also do this in the Interface Builder.

To disable Keyboard Suggestions on UITextField or UITextView — in the Attributes Inspector set Correction to No .

enter image description here

Solution 3 - Ios

I've created a UITextView category class with the following method:

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

    if (self.isFirstResponder) {
        [self resignFirstResponder];
        [self becomeFirstResponder];
    }
}

I wish there was a cleaner approach tho. Also, it assumes the auto-correction mode was Default, which may not be always true for every text view.

Solution 4 - Ios

In Swift 2:

myUITextField.autocorrectionType = UITextAutocorrectionType.No

Solution 5 - Ios

In Swift 4.x:

myUTTextField.autocorrectionType = .no

Solution 6 - Ios

As others have said, you can use:

textView.autocorrectionType = .no

but I've also noticed people struggling with actually making the autocomplete bar swap out, since if the textView is already the firstResponder when you change its autocorrectionType, it won't update the keyboard. Instead of trying to resign and reassign the firstResponder status to the textView to effect the change, you can simply call:

textView.reloadInputViews()

and that should hide the autocomplete bar. See https://developer.apple.com/documentation/uikit/uiresponder/1621110-reloadinputviews

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionriheView Question on Stackoverflow
Solution 1 - IosmihaiView Answer on Stackoverflow
Solution 2 - IosNikita KukushkinView Answer on Stackoverflow
Solution 3 - IosDZenBotView Answer on Stackoverflow
Solution 4 - IosNagendra RaoView Answer on Stackoverflow
Solution 5 - Iosyo2bhView Answer on Stackoverflow
Solution 6 - IosRanceView Answer on Stackoverflow