class ViewController1: BaseViewController {
var textView = UITextView.init()
var poem = [("Test ", 0.2), ("my ", 0.2), ("core ", 0.2), ("just ", 0.2), ("like ", 0.2), ("before", 0.2)]
func display(poem: [(word: String, delay: TimeInterval)]) {
guard let first = poem.first else { return }
UIView.transition(with: textView,
duration: first.delay,
options: .transitionCrossDissolve,
animations: { self.textView.text.append(first.word) },
completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + first.delay) {
self.display(poem: Array(poem.dropFirst()))
}
}
}
网友评论