CABasicAnimation change size of rect

Hi, I'm trying to resize my rect with CABasicAnimation and the animation go to up and not down How can I change it? Video: https://streamable.com/nw4ekc Thank you!

        let newFrame = NSRect(x: blueRect.frame.origin.x, y: blueRect.frame.origin.y - 100,width: blueRect.frame.size.width, height: 200)
        
        let animation = CABasicAnimation(keyPath: "bounds")
        animation.fromValue = NSValue(rect: blueRect.frame)
        animation.toValue = NSValue(rect: newFrame)
        animation.duration = 0.5 // Animation duration in seconds
        blueRect.layer?.add(animation, forKey: "sizeAnimation")
        
        // Update the rect view's size and origin
        blueRect.frame = newFrame

I think the issue is that the last line

   blueRect.frame = newFrame

is called immediately, just after animation starts.

If I understand your intent, you should call it when animation is completed.

See here: https://stackoverflow.com/questions/27882016/wait-for-swift-animation-to-complete-before-executing-code

how to use

override func animationDidStop(anim: CAAnimation!, finished flag: Bool) { }
CABasicAnimation change size of rect
 
 
Q