(Scale) Transform Animation on UITextView

My goal is to create a "bubble-up" animation to a UITextView that is being nested in a UIView card presented modally.

While the card appears, the UITextView doesn't seem to..is there some workaround for this? Below is the code I have tried thus far...

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    DispatchQueue.main.async {
        UIView.animate(withDuration: 1, delay: 0.1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: .curveEaseOut, animations: {
            self.cardView.transform = CGAffineTransform(scaleX: 1, y: 1)              
            self.messageTextView.transform = CGAffineTransform(scaleX: 1, y: 1)  
        }, completion: nil)            
    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    cardView.transform = CGAffineTransform(scaleX: 0, y: 0)
    messageTextView.transform = CGAffineTransform(scaleX: 0, y: 0)
}

2 answers

  • answered 2018-11-08 00:38 Duncan C

    I did a test and I had to add height and width constraints to my UITextViews or they collapse to zero size and aren't visible.

    Also note that you should use a small non-zero scale value like 0.01 for your small size rather than 0, at least for shrinking a view. If you try to animate a view's scale down to zero it disappears rather than shrinking.

    Edit:

    I also tried your spring damped animation, and found that with the values of usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8 that you're using, the spring effect is barely noticeable. If I dial the damping down to 0.5, the bouncing effect is better, but when animating the view shrinking, the view scale overshoots 0 scale and grows back upside-down slightly.

  • answered 2018-11-08 02:35 E.Coms

    I'm not sure the exact setting, so show the storyboard. I did not add the constrain but setNeedsLayout before animation. Hope it works for you.

    enter image description here

              override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            DispatchQueue.main.async {
                self.messageTextView.setNeedsLayout()
                UIView.animate(withDuration: 1, delay: 0.1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: .curveEaseOut, animations: {
                    self.cardView.transform = CGAffineTransform(scaleX: 1, y: 1)
                    self.messageTextView.transform = CGAffineTransform(scaleX: 1, y: 1)
                }, completion: nil)
            }
        }
    

    enter image description here