Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect of iOS 8 quicktype keyboard is opened or closed without notification

Tags:

ios

keyboard

ios8

I have us that attempts to display itself above the keyboard and should not move once the keyboard is opened.

I can adjust where it displays but with the quicktype keyboard I can't determine the height of the keyboard unless I know if the quicktype is opened or close. Is there any way I can determine this?

like image 541
madmik3 Avatar asked Sep 17 '14 18:09

madmik3


1 Answers

You should be using the keyboardWillShow: notification to adjust other views frames.

A notification is posted to keyboardWillShow: not only on becomeFirstResponder for a textView/Field but also when the user shows/hides the quick type keyboard.

once the keyboardWillShow: notification has been posted, the keyboard's frame can be captured by the UIKeyboardFrameEndUserInfoKey in the notification object.

An example of a textView that adjusts its frame based on the keyboard:

- (void)keyboardWillShow:(NSNotification *)notification
{
  CGRect keyboardRect = [[[notification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  UIViewAnimationCurve curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];

  [UIView animateWithDuration:duration animations:^{

    [UIView setAnimationCurve:curve];
    self.textViewVisualEffectView.frame = CGRectMake(self.textViewVisualEffectView.origin.x, self.view.height - keyboardRect.size.height - self.textViewVisualEffectView.height, self.textViewVisualEffectView.width, self.textViewVisualEffectView.height);

  } completion:^(BOOL finished) {

  }];
}
like image 116
adamesgie Avatar answered Oct 09 '22 09:10

adamesgie