I have a UIToolbar that lies at the bottom of my ViewController and moves to the top of the keyboard with animation as the keyboard slides up. In other words it moves with the keyboard. Now I am creating a way for the UITextView which is contained in the toolbar to resize it's height as the user types up newlines in the textView. So far I'm using this code in my class:
- (void)textViewDidChange:(UITextView *)textView
{
CGFloat fixedWidth = textView.frame.size.width;
CGFloat fixedWidthToolbar = self.navigationController.toolbar.frame.size.width;
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGSize newSizeToolbar = [self.navigationController.toolbar sizeThatFits:CGSizeMake(fixedWidthToolbar, MAXFLOAT)];
CGRect newFrame = textView.frame;
CGRect newToolbarFrame = self.navigationController.toolbar.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
newToolbarFrame.size = CGSizeMake(fmaxf(newSizeToolbar.width, fixedWidthToolbar), newSizeToolbar.height);
textView.frame = newFrame;
self.navigationController.toolbar.frame = newToolbarFrame;
}
Everything works except the tool bar. By working, I mean that the UITextView grows whenever a newline is added to it(the user it typing lots of text). The problem here is that I'm not seeing the toolbar grow in size like the textView is. I believe my problem is that I used the same code for resizing the toolbar that I used for resizing the textview.
EDIT: The general idea here is to allow both the UITextView and the UIToolbar resize at the same time, allowing the user to see there text being written in the UITextView.
What can I do to achieve this goal? What am I doing wrong?