Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvkiet/433a73c4a4ecf8a7f279 to your computer and use it in GitHub Desktop.
Save nvkiet/433a73c4a4ecf8a7f279 to your computer and use it in GitHub Desktop.
UITableViewCell with UITextView height in iOS 7?
http://stackoverflow.com/questions/18368567/uitableviewcell-with-uitextview-height-in-ios-7
- (void)textViewDidChange:(UITextView *)textView {
if ([textView getContentHeight] > 31) {
self.noteHeightLayoutConstraint.constant = [textView getContentHeight] + 20;
[self.tableView beginUpdates];
[self.tableView endUpdates];
[self scrollToCursorForTextView:textView];
}
}
- (void)textViewDidBeginEditing:(UITextView *)textView {
[self scrollToCursorForTextView:textView];
}
- (void)scrollToCursorForTextView:(UITextView *)textView {
CGRect cursorRect = [textView caretRectForPosition:textView.selectedTextRange.start];
cursorRect = [self.tableView convertRect:cursorRect fromView:textView];
if (![self rectVisible:cursorRect]) {
cursorRect.size.height += 8;
[self.tableView scrollRectToVisible:cursorRect animated:NO];
}
}
- (BOOL)rectVisible:(CGRect)rect {
CGRect visibleRect;
visibleRect.origin = self.tableView.contentOffset;
visibleRect.origin.y += self.tableView.contentInset.top;
visibleRect.size = self.tableView.bounds.size;
visibleRect.size.height -= self.tableView.contentInset.top + self.tableView.contentInset.bottom;
return CGRectContainsRect(visibleRect, rect);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment