如何在UITextView中像提词提示器中快速滚动文本?

时间:2018-11-17 11:20:09

标签: swift uitextview uidynamicanimator

我想像提词提示滚动一样滚动文本。我已经读过有关42的信息,但不清楚std::map::emplace()是否有多行内容。

赞赏您的建议或代码片段以实现此目标。

1 个答案:

答案 0 :(得分:1)

使用递归方法,我们可以使用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)

请注意,每行滚动后都会有一个延迟。