When a user is typing inside of my textView, I want to know when a new line begins, as I want to change the height of my textView when this happens. That said, I know how to accomplish this if the return button is hit - but if a new line just begins automatically (e.g. a new line is started simply because a user keeps typing), this doesn't seem as simple. The code I'm using below works successfully when 'return' is tapped - but I can't seem to get it to detect any sort of line change otherwise.
Hope I worded this well enough. Thanks!
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
self.replyField.text=[NSString stringWithFormat:@"%@\n",self.replyField.text];
CGFloat fixedWidth = self.replyField.frame.size.width;
CGSize newSize = [self.replyField sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = self.replyField.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
self.replyField.frame = newFrame;
CGRect newFrame1 = self.upView.frame;
NSLog(@"WHAT IS THE NEW HEIGHT %f", newFrame1.size.height);
self.upView.frame = CGRectOffset(self.upView.frame, 0, -15);
return NO;
}
// For any other character return TRUE so that the text gets added to the view
return YES;
}