UITextView scrolling caret to visible text on Devi

2019-09-17 20:34发布

this scrollToCaretInTextView function was working in Swift 2, but on converting to Swift 3, it has an error message that I can't find a solution to.

Here is the code:

 @IBOutlet weak var emailBody: UITextView!

     override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
 scrollToCaretInTextView(textView: emailBody, animated: true)
    }

 func scrollToCaretInTextView(textView:UITextView, animated:Bool) {
 var rect = emailBody.caretRectForPosition((textView.selectedTextRange?.end)!)
 rect.size.height += textView.textContainerInset.bottom
 textView.scrollRectToVisible(rect, animated: animated)
    }

The error message is:

Value of Type 'UITextView' has no member 'caretRectForPosition'

How can I fix this please?

Thanks!

1条回答
神经病院院长
2楼-- · 2019-09-17 20:56

In Swift 3 method signature is changed like caretRect(for:)

var rect = emailBody.caretRect(for: textView.selectedTextRange!.end)
查看更多
登录 后发表回答