Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS, Keyboard Predictive bar visibility

I have some instance of UITextView and I want this textView to occupy all empty vertical space when keyboard is shown. The problem is that I do not know what height will keyboard take as it has predictive bar in iOS 8 and its actual height can be changed by user when keyboard was already shown. I do not want to change textView's autocorrectionType. I am fine with that bar, just want to handle it in correct way.

So the question: Is there any possibility to know if this bar is visible or not? Is there any was to trigger user swipe to show/hide this bar?

Thanks in advance.

like image 476
B.S. Avatar asked May 27 '15 08:05

B.S.


People also ask

How do I turn on text prediction on iPhone?

Use predictive textTap Keyboard Settings, then turn on Predictive. Or go to Settings > General > Keyboard, and turn Predictive on or off.

What is predictive in iPhone Keyboard?

As you type text on the iPhone keyboard, you see predictions for your next word, emoji that could take the place of your word, and other suggestions based on your recent activity and information from your apps (not available for all languages).

What's predictive on Keyboard?

The Predictive text feature suggests or corrects words as you type text on the Samsung keyboard. This allows you to enter text quickly and easily by suggesting and changing words as you type.

Why is my predictive text not working Apple?

Step 1: Open the Settings app on your iPhone and navigate to the General section. Step 2: Now, tap on Keyboard. Step 3: Scroll down and ensure that the toggles next to Check Spelling and Predictive are enabled.


3 Answers

You can change Setting autocorrectionType to UITextAutocorrectionTypeNo on the UITextView (or correction to NO in IB) disables autocorrect as well as the predictive text bar in iOS 8. There doesn't appear to be a way to disable just the predictive bar however.

yourTextView.autocorrectionType = UITextAutocorrectionTypeNo;

enter image description here

Edit:

check this I think it is gonna be helpful

like image 106
Omarj Avatar answered Sep 21 '22 16:09

Omarj


Well you can handle when the user swipe to show/hide the bar(prediction bar) of UIKeyboard,

First step

declare a keyboard notification in viewdidLoad() and declare a global variable kbSize

float kbSize;

 - (void)viewDidLoad
{
     kbSize=0.0;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];

--- rest of your code here---
}

Second step

Now in keyboardWillShowNotification() method do the following

#pragma mark - Notifications
- (void)keyboardWillShowNotification:(NSNotification *)aNotification{

       NSDictionary *infos  = aNotification.userInfo;
       NSValue      *value = infos[UIKeyboardFrameEndUserInfoKey];

       CGRect rawFrame      = [value CGRectValue];
       CGRect keyboardFrame = [self.view convertRect:rawFrame fromView:nil];


     if(kbSize==0.0)
    {

       kbSize=keyboardFrame.size.height;
       NSLog(@"prediction bar is visible");


     }

     else if(keyboardFrame.size.height<kbSize)
      { 

          NSLog(@"prediction bar is not visible");
          --- rest of your code here, how you want to change your view when bar is not visible ---

      }

     else
      {

          NSLog(@"prediction bar is visible");
           --- rest of your code here, how you want to change your view when bar is  visible ---

      }

}

Conclusion:- As keyboardWillShowNotification will always fire whenever the user does some editing with your text-fields or whenever user will swipe to hide or show the prediction bar.

So we just have to check the height of keyboard whenever keyboardWillShowNotification will fire,so if the user swipe the bar to hide then automatically the keyboard height will decrease and we are already storing the height of keyboard in variable kbSize, we just have to check whether current height of keyboard is less than then the stored kbSize . So by this way we can check at runtime whether bar is visible or not or user swipe to hide the bar.

like image 31
Vizllx Avatar answered Sep 21 '22 16:09

Vizllx


You can get the keyboard height by adding an observer:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillChange:", name: UIKeyboardDidChangeFrameNotification, object: nil)
//Method
func keyboardWillChange(notification: NSNotification){
        println(notification.userInfo?.description)

 }
like image 23
Ajay Avatar answered Sep 23 '22 16:09

Ajay