我正在开发一个应用程序,其中我有一个UITableview
,每个单元格中有一个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;
}];
}
}