【问题标题】:Scrolling text in UItextfield when cursor is at the corner of uitextfield当光标位于 uitextfield 的角落时,在 UItextfield 中滚动文本
【发布时间】:2013-08-27 09:29:19
【问题描述】:

我正在尝试在平移手势上移动 UITextfield 的光标。但我面临一些问题。

我有一个 UITextfield 和 UIView(与 UITextfield 大小相同)。

我在 UIView 上添加了平移手势,因为我想通过在 UIView 上拖动手指来移动 UITextfield 的光标位置

但是当我移动光标位置并且光标出现在 UITextfield 的角落时,不会发生文本滚动。

谁能帮我解决这个问题?

代码:

-(void)panGesture:(UIPanGestureRecognizer *)pan
{

CGPoint translation = [pan translationInView:btnMove];
CGPoint vel = [pan velocityInView:btnMove];

UITextRange *range = txtSearch.selectedTextRange;
NSInteger endOffset = [txtSearch offsetFromPosition:txtSearch.beginningOfDocument toPosition:range.end];

if (vel.x > 0)
{

    endOffset = endOffset + 1;

    NSLog(@"right - %ld",(long)endOffset);

}
else{

    endOffset = endOffset - 1;

    NSLog(@"left - %ld",(long)endOffset);

}

UITextPosition *from = [txtSearch positionFromPosition:[txtSearch beginningOfDocument] offset:endOffset];
UITextPosition *to = [txtSearch positionFromPosition:[txtSearch beginningOfDocument] offset:endOffset];

txtSearch.selectedTextRange = [txtSearch textRangeFromPosition:from toPosition:to];

}

【问题讨论】:

    标签: ios objective-c gesture


    【解决方案1】:

    我猜这是针对 iOS 6 的?我对 7 没有任何问题,但 6 一直是熊。这对我有用,但我不知道为什么。设置您选择的文本范围后,尝试添加此行:

    [txtSearch setBaseWritingDirection:UITextWritingDirectionNatural forRange:txtSearch.selectedTextRange];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 2010-12-02
      • 1970-01-01
      • 2012-07-26
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多