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?
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) {
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With