Swift 中同一 UIView 的多个动画
Multiple Animations For Same UIView in Swift
我正在尝试为我的图像视图添加多个动画,但其中只有一个是动画的。请检查以下代码。我为我的图像视图创建了缩放和旋转动画,但只有在 运行 以下代码时我才能看到缩放动画。
//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)
发生了轮换,但持续时间较短
group.duration = 0.2
当更改为 5 秒时参见
在完成时你可以放置你的动画,当完成一个时,等待第二个..等等
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
})
})
我正在尝试为我的图像视图添加多个动画,但其中只有一个是动画的。请检查以下代码。我为我的图像视图创建了缩放和旋转动画,但只有在 运行 以下代码时我才能看到缩放动画。
//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)
发生了轮换,但持续时间较短
group.duration = 0.2
当更改为 5 秒时参见
在完成时你可以放置你的动画,当完成一个时,等待第二个..等等
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
})
})