我想滚动我的文字就像提词器滚动一样。我读过关于UIDynamicAnimation的文章,但对多行的UITextView不是很清楚。
感谢您的建议或代码片段来实现这一点。
发布于 2018-11-19 09:34:19
通过使用递归方法,我们可以使用UIView.animate(withDuration:animations:completed)对每个行滚动进行动画处理,直到到达textView的末尾。
func animateRowWith(duration: TimeInterval, rowHeight: CGFloat) {
if self.textView.contentOffset.y < self.textView.contentSize.height - self.textView.frame.size.height {
UIView.animate(withDuration: duration, animations: {
self.textView.contentOffset = CGPoint(x: self.textView.contentOffset.x, y: self.textView.contentOffset.y + rowHeight)
}) { (_) in
self.animateRowWith(duration: duration, rowHeight: rowHeight)
}
}
}正在调用它:
animateRowWith(duration: 1.0, rowHeight: self.textView.font?.lineHeight ?? 0)。
请注意,每行滚动后都会有延迟。
https://stackoverflow.com/questions/53350715
复制相似问题