Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

ios - How can I show tapped text in UITextView without hidden behind the keyboard

I am starting to learn iOS recently and now I am proceeding project to improve my skills. In this project, I want users to to edit UITextView and when user touch UITextView I want users to edit the text at the point that they touched.

The problem when the text is way below, text is hidden by the keyboard when keyboard appears. When it happens, I want to move textView above so tapped location is just above the keyboard.

I've been googling all day but I couldn't find any suitable solution

The code below is most common solution in google but I couldn't understand what currentPoint and rect stands for. It is giving me values but I couldn't understand

If there's another way to solve this issue or help me understand code it would be very helpful

func textViewDidBeginEditing(_ textView: UITextView) {
        let startPoint = textView.beginningOfDocument
        let selectRange = textView.selectedTextRange
        
        guard let range = selectRange else {
            return
        }
        var currentPoint = textView.offset(from: startPoint, to: range.start)
        let rect = textView.caretRect(for: range.end)
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...