0

I am developing an chat app, i have used tableview to display the messages sent and receive and a view with textfield and add button at the bottom. On clicking add button action sheet is displayed with options Everything works fine except, when i click on add button and tap cancel button of action sheet and then tap on textfield....tableview does not scroll up when keyboard is shown

enter image description here

Below is the code for keyboardwillshow notification

KeyboardWillShow :

NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey];
    NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];

    CGRect keyboardBounds;
    [keyboardBoundsValue getValue:&keyboardBounds];
    NSNumber *duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSNumber *curve = [notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];

    // Need to translate the bounds to account for rotation.
    keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];

    CGRect containerFrame = viewDummy.frame;// viewDummy is the view where keyboard, add button and speak button is displayed
    containerFrame.origin.y = self.view.bounds.size.height - (keyboardBounds.size.height + containerFrame.size.height);
    NSLayoutConstraint *constPaddingwithViewTable.constant = keyboardBounds.size.height + containerFrame.size.height;

    // animations settings
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:[duration doubleValue]];
    [UIView setAnimationCurve:[curve intValue]];

    // set views with new info
    viewDummy.frame = containerFrame;


    // commit animations
    [UIView commitAnimations];

}
Vidhyanand
  • 5,369
  • 4
  • 26
  • 59

2 Answers2

0

There seems to have been some good questions and answers on this before.

The following seems particularly good: How to make a UITextField move up when keyboard is present?

This also references the Apple docs on the subject of keyboard and content scrolling. It includes a fix for their example code. Link

Community
  • 1
  • 1
Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28
-1

Add this below setting your constraint [self.view layoutIfNeeded];

Bogdan Matveev
  • 518
  • 2
  • 14