[英]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)
in your completion you can put your animations, when finish one, wait second.. and etc 在完成时,您可以放动画,在完成时放动画,等待第二个..等等
let myImage = UIImageView()
UIView.animate(withDuration: 1.0, animations: {
let rotation: CABasicAnimation = CABasicAnimation(keyPath:
"transform.rotation.y")
rotation.toValue = 0
rotation.fromValue = 2.61
}, completion: { (value: Bool) in
UIView.animate(withDuration: 1.0, animations: {
//you can here put your other animation
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.