CGAffineTransform animation problems

Because apparently I haven’t used this particular animation until now, I am not sure if this is supposed to be this way, though in my opinion it shouldn’t.

Let us have a view and a subview that we want to animate. For scaling purposes, the subview is initially scaled down by 4 (scaleFactor = 0.25 ). I want an animation that scales the subview back up to its original size while translating it y points by the Y axis. Intuitively:

subview.transform = CGAffineTransform.init(scaleX: 0.25, y: 0.25)

UIView.animate(withDuration: 10.0) {

    subview.transform = CGAffineTransform.init(translationX: 0, y: y)

I expect the animation to progress this way:

let scaleFactor = 1.0 - 0.75 * (1 - progress)

subview.transform = CGAffineTransform.init(scaleX: scaleFactor, y: scaleFactor).concatenating(CGAffineTransform.init(translationX: 0, y: y * progress))

However, the animation performs in an unexpected way, instantly translating by some distance and then continues normally.

Playground code:

import UIKit

import PlaygroundSupport

let v = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 700, height: 700))

let v1 = UIView()

v.backgroundColor = .white
v1.backgroundColor = .blue
v1.translatesAutoresizingMaskIntoConstraints = false


v1.heightAnchor.constraint(equalToConstant: 140).isActive = true
v1.widthAnchor.constraint(equalTo: v1.heightAnchor).isActive = true

v1.topAnchor.constraint(equalTo: v.topAnchor)
v1.centerXAnchor.constraint(equalTo: v.centerXAnchor).isActive = true

v1.transform = CGAffineTransform.init(scaleX: 0.25, y: 0.25)

UIView.animate(withDuration: 10.0) {
    v1.transform = CGAffineTransform.init(translationX: 0, y: 500)

PlaygroundPage.current.liveView = v

Developer Forums thread

Best regard, Adrian.

This is a category for core libraries though, UIKit should be OK?

Although I will post to the developer forums as well, that’s a good idea.

UIKit is not part of core libraries, only parts of Foundation and GCD is.

Will take that into account.

1 Like

Please also note that this is not a section for development with core libraries either, but development of the core libraries.