我正在为tvOS开发一个小应用程序,在这里我需要展示一个UITextView。
不幸的是,有时这篇文章不能适应屏幕,这就是为什么我需要一种方式滚动到它的底部,以编程方式。
我尝试使用以下代码:
self.setContentOffset(offset, animated: true)它实际上是按预期工作的,只是我需要处理动画速度,这样用户才能实际阅读;目前它太快了。
这就是我想要做的,但没有取得什么成功:
let offset = CGPoint(x: 0, y: contentSize.height - bounds.size.height)
UIView.animate(withDuration: 4, animations: {
self.setContentOffset(offset, animated: false)
})我需要一种方法来保持文本的位置,并滚动它,以显示缺失的线条。
我在UITextView中使用UIScrollView。
谢谢。
发布于 2017-12-06 13:49:48
如果有人在寻找解决方案,这就是我最后使用的:
var textTopDistance = 100
//calculate height of the text not being displayed
textNotVisibleHeight = descriptionLabel.contentSize.height - scrollView.bounds.size.height
func scrollText() {
//start new thread
DispatchQueue.main.async() {
//animation
UIView.animate(withDuration: 6, delay: 2, options: UIViewAnimationOptions.curveLinear, animations: {
//set scrollView offset to move the text
self.scrollView.contentOffset.y = CGFloat(self.textNotVisibleHeight - self.textTopDistance)
}, completion: nil)
}
}我知道这并不完美,但至少它是按预期运作的。
https://stackoverflow.com/questions/47655666
复制相似问题