3

I am working on an application in which I have a UITableview and in each cell a UITextview. When I select a position, if the cursor position is not equal to that position it will jump upward using two line jump and after reaching that position, on each line-wrap it will take one-line jump only. But two line jump is not working. Here is the code.

CGPoint cursorPosition = [textView caretRectForPosition:textView.selectedTextRange.start].origin;
CGRect cellYPos = [tableView rectForRowAtIndexPath:indexpath];

float newposition = cellYPos.origin.y - self.tableView.contentOffset.y;
newposition += cursorPosition.y;

if(cursorPreviousPosition < cursorPosition.y)
{
    cursorPreviousPosition = cursorPosition.y;
    CGPoint contentOffset = self.tableView.contentOffset;

    if(previousLocation > contentOffset.y)
    {
        previousLocation = contentOffset.y;
    }

    if (contentOffset.y < 0)
        contentOffset.y = 0;

    if(self.isLandScape)
    {
        if(newposition > 55 && newposition <= 106)
        {
            if(newposition - 55 > 21)
            {
                contentOffset.y += textView.font.lineHeight;
                contentOffset.y += textView.font.lineHeight;
            }
            else if(newposition - 55 == 21)
            {
                contentOffset.y += textView.font.lineHeight;
            }
            else
            {
                contentOffset.y += (newposition - 55);
            }
            [UIView animateWithDuration:0.2 animations:^{
                self.tableView.contentOffset = contentOffset;
            }];
        }
        else if(newposition >= 55)
        {
            contentOffset.y += textView.font.lineHeight;
            [UIView animateWithDuration:0.2 animations:^{
                self.tableView.contentOffset = contentOffset;
            }];
        }
    }
    else
    {
        if(newposition > 108 && newposition <=196)
        {
            if(newposition - 108 > 21)
            {
                NSLog(@"Two lines jump");
                contentOffset.y += textView.font.lineHeight;
                contentOffset.y += textView.font.lineHeight;
            }
            else if(newposition - 108 == 21)
            {
                contentOffset.y += textView.font.lineHeight;
            }
            else
            {
                contentOffset.y += (newposition - 108);
            }

            [UIView animateWithDuration:0.2 animations:^{
                self.tableView.contentOffset = contentOffset;
            }];
        }
        else if(newposition >= 108)
        {
            contentOffset.y += textView.font.lineHeight;
            [UIView animateWithDuration:0.2 animations:^{
                self.tableView.contentOffset = contentOffset;
            }];
        }
    }
Vidya Murthy
  • 530
  • 1
  • 8
  • 22
imran ali
  • 33
  • 4

0 Answers0