【问题标题】:Multiple Animations For Same UIView in SwiftSwift 中同一 UIView 的多个动画
【发布时间】:2018-10-22 17:21:14
【问题描述】:

我正在尝试为我的图像视图添加多个动画,但其中只有一个是动画的。请检查以下代码。我为我的图像视图创建了缩放和旋转动画,但只有在运行以下代码时我才能看到缩放动画。

//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) 

【问题讨论】:

    标签: ios swift animation swift4 cabasicanimation


    【解决方案1】:

    轮换发生,但持续时间较少

    group.duration = 0.2
    

    当改为 5 秒时见

    【讨论】:

      【解决方案2】:

      在你的完成中,你可以放置你的动画,当完成一个,等待第二个......等等

         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
              })
          })
      

      【讨论】:

      猜你喜欢
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多