1

I'm working on a chat app.When my keyboard appear I want to resize the table view and text view according to the keyboard frame.

The problem is that my table view automatically resize and reposition when my key board appear.

My code is..

-(void)KeyboardWillShow:(NSNotification *)keyboardInfo
{
    @try {
        NSDictionary *userInfo = keyboardInfo.userInfo;
        // Get keyboard size.
        NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
        CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];

        // Get keyboard animation.

        NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
        NSTimeInterval animationDuration = durationValue.doubleValue;

        NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
        UIViewAnimationCurve animationCurve = curveValue.intValue;
[UIView animateWithDuration:animationDuration delay:0.0 options:(animationCurve<<16) animations:^{

    [self.messageView setFrame:CGRectMake(self.messageView.frame.origin.x, self.view.frame.size.height-keyboardEndFrame.size.height-self.messageView.frame.size.height, self.messageView.frame.size.width, self.messageView.frame.size.height)];

   [self.tableView setFrame:CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.view.frame.size.height-keyboardEndFrame.size.height-self.messageView.frame.size.height-self.tableView.frame.origin.y)];
} completion:nil];
    }

    @catch (NSException *exception) {

   NSLog(@"Error in func:%s, line:%d with reason:%@",__func__,__LINE__,exception.reason);
    }

}

my output is below image and i want other image[![][1]]2

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Saurabh Jain
  • 1,688
  • 14
  • 28

2 Answers2

0

Take an outlet of bottom constraint of tableview and programatically change it like this

tablebottomConstraint.constant =  keyboardEndFrame.size.height+self.messageView.frame.size.height
Ahmad Ishfaq
  • 914
  • 1
  • 8
  • 10
0

You cold use the table inset, modyfying the bottom inset of the content of tableView :

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardEndFrame.size.height + self.messageView.frame.size.height, 0);
Alberto Scampini
  • 798
  • 9
  • 27