私はUITextView
を持っていますが、私がしようとしているのは2秒後に別のテキストを追加することです。 2秒ごとにテキストが消え、別のテキストが表示されます。私は2つのテキストだけでそれをしましたが、もしそれ以上のものをしたいのであればどうしますか?一定の時間内にUITextViewからテキストを変更します
次のコードは、私はそれをやった方法を紹介します:
@IBOutlet weak var label: UILabel!
var isTextOne = true
var textOne: String = "one"
var textTwo: String = "two"
var textThree: String = "three"
@IBOutlet weak var quoteView: UIView!
var textTimer: Timer!
func toggleText() {
label.text = isTextOne ? textTwo:textOne
isTextOne = !isTextOne
fadeViewInThenOut(view: quoteView, delay: 2)
}
func fadeViewInThenOut(view : UIView, delay: TimeInterval) {
let animationDuration = 0.25
// Fade in the view
UIView.animate(withDuration: animationDuration, animations: {() -> Void in
view.alpha = 1
}) { (Bool) -> Void in
// After the animation completes, fade out the view after a delay
UIView.animate(withDuration: animationDuration, delay: delay, options: .curveEaseInOut, animations: {() -> Void in
view.alpha = 0
}, completion: nil)
}
}