3

我正在开发一个应用程序,其中我有 aUITableview和每个单元格 a UITextview。当我选择一个位置时,如果光标位置不等于该位置,它将使用两行跳转向上跳转,并且在到达该位置后,在每个换行时它只会进行一行跳转。但是两行跳转不起作用。这是代码。

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;
            }];
        }
    }
4

0 回答 0