Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)textViewDidChange:(UITextView *)textView {
- dispatch_async(dispatch_get_main_queue(), ^{
- [UIView setAnimationsEnabled:NO];
- [self.textViewUpdaterDelegate didChangeTextViewForCell:self];
- [UIView setAnimationsEnabled:YES];
- });
- }
- - (void)didChangeTextViewForCell:(nonnull SectionQuestionCell *)cell {
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
- NSInteger index = indexPath.row;
- Question *question = self.questions[index];
- question.hint = cell.dataTextView.text;
- //to update the table view cell height
- [self.tableView beginUpdates];
- [self.tableView endUpdates];
- CGRect cursor = [cell.dataTextView caretRectForPosition:cell.dataTextView.selectedTextRange.start];
- CGRect convertedCursor = [cell.dataTextView convertRect:cursor toView:self.tableView.superview];
- CGFloat allHeight = self.tableView.superview.frame.size.height;
- CGFloat cursorEnd = convertedCursor.origin.y + convertedCursor.size.height;
- CGFloat visibleHeight = allHeight - self.keyboardHeight;
- if (visibleHeight >= cursorEnd && cursorEnd > 0) {
- //it means it is in the visible part
- return;
- }
- CGFloat difference = 0;
- if (cursorEnd >= 0) {
- difference = cursorEnd - visibleHeight;
- } else {
- difference = -convertedCursor.origin.y;
- }
- if (indexPath.row == self.questions.count - 1 && self.tableView.contentSize.height > self.tableView.frame.size.height) {
- [self.tableView beginUpdates];
- [self.tableView endUpdates];
- [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
- } else if (difference != 0) {
- [UIView animateWithDuration:0.3 animations:^{
- self.tableViewTopConstraint.constant -= difference;
- }];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement