jshapy8 jshapy8 - 3 years ago 111
Swift Question

iOS/Swift: Use UIView.animate to animate text getting added/removed from UITextView

I am adding and removing attributed text from a

UITextView
. I wish to use
UIView.animate
to add an animation to when text is appended to the text view and when that appended text is removed from the text view. So far, I have this, but it does not cause any noticeable animation on the text view:

UIView.animate(withDuration: 1, delay: 0, options: .CurveLinear, animations: {
self.view.layoutIfNeeded()
self.textView.attributedText = newAttributedText
}, completion: { finished in
print("Animation completed")
}

// prints "Animation completed", but no animation occurs

Answer Source

You cannot animate changing of text in that manner. There is a list of animatable properties of CALayer class and UIView class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download