UITextView scrolling caret to visible text on Device Rotation in Swift 3

99封情书 提交于 2019-12-25 05:20:16

问题


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:


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

var rect = emailBody.caretRect(for: textView.selectedTextRange!.end)


来源:https://stackoverflow.com/questions/43321500/uitextview-scrolling-caret-to-visible-text-on-device-rotation-in-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!