I'm developing a chat app in ios and I have custom tableview and UIView with some textfield ane button on the bottom. I would like to move UIView and Tableview with keyboard when Textfield is activated. I have this obserer :
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
and then the keyboardWasShown method :
- (void)keyboardWasShown:(NSNotification*)aNotification{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSNumber *number = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
double duration = [number doubleValue];
[UIView animateWithDuration:duration animations:^{
CGRect frame = textInputView.frame;
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
self.kHeight = kbSize.height;
}
else if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
self.kHeight = kbSize.width;
}
NSLog(@"keyboard up y =%f",self.kHeight);
frame.origin.y -= self.kHeight;
textInputView.frame = frame;
frame = bubbleTable.frame;
frame.size.height -= self.kHeight;
bubbleTable.frame = frame;
}];
It is working, but you notice that UIview doesn't move smoothly like in facebook or viber app. So I would like to ask what is the common approach for this. Thank you a lot!