Search code examples
iosswiftanimationswift4cabasicanimation

Multiple Animations For Same UIView in Swift


I am trying to add multiple animations for my image view, but only one of them is animated. Please check the below code. I created scale and rotate animations for my image view but only i see the scale animation when run the below code.

//Rotate animation
let rotation: CABasicAnimation = CABasicAnimation(keyPath: 
"transform.rotation.y")
rotation.toValue = 0
rotation.fromValue = 2.61

//Scale animation
let scale: CABasicAnimation = CABasicAnimation(keyPath: "transform.scale")
scale.toValue = 1
scale.fromValue = 0

//Adding animations to group
let group = CAAnimationGroup()
group.animations = [rotation,scale]
group.duration = 0.2

myImage.layer.add(group, forKey: nil) 

Solution

  • The rotation occurs but the duration is less to notice

    group.duration = 0.2
    

    when changed to 5 seconds see

    enter image description here