I want to resize the text view when the keyboard appears. The code I have is below. I have auto layout on, hence using a constraint of textView->bottom space from superview and referencing it via IBOutlet distanceFromBottom.
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
NSDictionary* d = [notification userInfo];
CGRect r = [d[UIKeyboardFrameEndUserInfoKey] CGRectValue];
r = [textView convertRect:r fromView:Nil];
if(IS_IPHONE_6||IS_IPHONE_6P)
distanceFromBottom.constant = r.origin.y+78;
else if(IS_IPHONE_5)
distanceFromBottom.constant = r.origin.y+183;
}];
}
The code above works perfect. What I don't understand is why I need to add +78 for iPhone6 or 183 for iPhone5. These two values I came with trial and error. If I don't add these, the textView extends below the keyboard. Please help me solve this mystery.