Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. -(void)textViewDidChange:(UITextView *)textView {
  2.  
  3. dispatch_async(dispatch_get_main_queue(), ^{
  4. [UIView setAnimationsEnabled:NO];
  5. [self.textViewUpdaterDelegate didChangeTextViewForCell:self];
  6. [UIView setAnimationsEnabled:YES];
  7. });
  8.  
  9. }
  10.  
  11. - (void)didChangeTextViewForCell:(nonnull SectionQuestionCell *)cell {
  12.  
  13. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
  14. NSInteger index = indexPath.row;
  15. Question *question = self.questions[index];
  16.  
  17. question.hint = cell.dataTextView.text;
  18.  
  19. //to update the table view cell height
  20. [self.tableView beginUpdates];
  21. [self.tableView endUpdates];
  22.  
  23. CGRect cursor = [cell.dataTextView caretRectForPosition:cell.dataTextView.selectedTextRange.start];
  24. CGRect convertedCursor = [cell.dataTextView convertRect:cursor toView:self.tableView.superview];
  25.  
  26. CGFloat allHeight = self.tableView.superview.frame.size.height;
  27. CGFloat cursorEnd = convertedCursor.origin.y + convertedCursor.size.height;
  28. CGFloat visibleHeight = allHeight - self.keyboardHeight;
  29. if (visibleHeight >= cursorEnd && cursorEnd > 0) {
  30. //it means it is in the visible part
  31. return;
  32. }
  33.  
  34. CGFloat difference = 0;
  35. if (cursorEnd >= 0) {
  36. difference = cursorEnd - visibleHeight;
  37. } else {
  38. difference = -convertedCursor.origin.y;
  39. }
  40.  
  41. if (indexPath.row == self.questions.count - 1 && self.tableView.contentSize.height > self.tableView.frame.size.height) {
  42. [self.tableView beginUpdates];
  43. [self.tableView endUpdates];
  44. [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
  45. } else if (difference != 0) {
  46. [UIView animateWithDuration:0.3 animations:^{
  47. self.tableViewTopConstraint.constant -= difference;
  48. }];
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement