Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell中的UITextView如何滚动表格视图以在键入时保持光标可见_Ios_Swift_Uitableview_Uitextview - Fatal编程技术网

Ios UITableViewCell中的UITextView如何滚动表格视图以在键入时保持光标可见

Ios UITableViewCell中的UITextView如何滚动表格视图以在键入时保持光标可见,ios,swift,uitableview,uitextview,Ios,Swift,Uitableview,Uitextview,我有一个自定义的UITableViewCell,其中包含UITextView。这间牢房相当大。如何自动滚动表格以确保当前选择点始终可见 注意UITextView是单元格的大小,因此它不会自动滚动自身 我可以在selectedTextRange上调用firstRectForRange,但如果插入点在末尾,则这不起作用(对于CGRect,您将获得inf、inf、0,0)。如果我有rect,我可以计算表中的偏移量并调整其滚动内容偏移量。有没有一个好方法可以做到这一点,或者搞乱contentOffset

我有一个自定义的UITableViewCell,其中包含UITextView。这间牢房相当大。如何自动滚动表格以确保当前选择点始终可见

注意UITextView是单元格的大小,因此它不会自动滚动自身


我可以在selectedTextRange上调用firstRectForRange,但如果插入点在末尾,则这不起作用(对于CGRect,您将获得inf、inf、0,0)。如果我有rect,我可以计算表中的偏移量并调整其滚动内容偏移量。有没有一个好方法可以做到这一点,或者搞乱contentOffset是唯一的方法?

这方面运气好吗?我在同样的情况下遇到了麻烦。我现在做的是通过使用

[textView caretRectForPosition:textView.selectedTextRange.end]
然后尝试从

convertRect: fromView:

在文本ViewDidChange中使用此选项

if let confirmedTextViewCursorPosition = textView.selectedTextRange?.end {

            let caretPosition = textView.caretRect(for: confirmedTextViewCursorPosition)
            var textViewActualPosition = tableView.convert(caretPosition, from: textView.superview?.superview)
            textViewActualPosition.origin.y += 20.0 // give the actual padding of textview inside the cell
            tableView.scrollRectToVisible(textViewActualPosition, animated: false)

        }