Animate UIImage in UIImageView Up & Down (Like it's hovering) Loop

前端 未结 4 1404
情深已故
情深已故 2021-02-04 13:45

Hello I have an image that I\'d like to move up and down (Up 10 pixels and down 10 pixels) so that my image appears to be hovering. How can I do this with simple animation thank

4条回答
  •  自闭症患者
    2021-02-04 14:35

    For Swift 3, Swift 4 and Swift 5:

    let hover = CABasicAnimation(keyPath: "position")
        
    hover.isAdditive = true
    hover.fromValue = NSValue(cgPoint: CGPoint.zero)
    hover.toValue = NSValue(cgPoint: CGPoint(x: 0.0, y: 100.0))
    hover.autoreverses = true
    hover.duration = 2
    hover.repeatCount = Float.infinity
        
    myView.layer.add(hover, forKey: "myHoverAnimation")
    

提交回复
热议问题