我的代码右动画向下滚动,但只是停在我放置 y 坐标的位置。我希望动画继续到 textview 的最底部。
UIView.animate(withDuration: 9) {
self.textView.contentOffset = CGPoint(x: 0, y: 100)
}
Best Answer-推荐答案 strong>
使用 scrollRangeToVisible 。
Playground 示例:
import UIKit
import PlaygroundSupport
func scrollTextViewToBottom(_ textView: UITextView) {
if(textView.text.characters.count > 0 ) {
guard let text = textView.text else {
return
}
let bottom = NSRange(location: text.characters.count - 1, length: 1)
textView.scrollRangeToVisible(bottom)
}
}
var textView = UITextView(frame: CGRect(x: 0, y: 0, width: 200, height: 300))
textView.text = "start long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts long texts end"
PlaygroundPage.current.liveView = textView
scrollTextViewToBottom(textView)
关于ios - 使用动画滚动 textView 的底部,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/44741912/
|