Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在swift中创建圆的运动动画_Swift_Xcode - Fatal编程技术网

如何在swift中创建圆的运动动画

如何在swift中创建圆的运动动画,swift,xcode,Swift,Xcode,所以我的问题是,我想要一个圆的运动动画,它从左向右移动。圆的创建方式如下: let point = CGPoint.init(x: 10, y: 10) let circlePath = UIBezierPath(arcCenter: point, radius: CGFloat(20), startAngle: CGFloat(0), endAngle: CGFloat(Double.pi * 2), clockwise: true) let shapeLayer = CAShapeLayer

所以我的问题是,我想要一个圆的运动动画,它从左向右移动。圆的创建方式如下:

let point = CGPoint.init(x: 10, y: 10)
let circlePath = UIBezierPath(arcCenter: point, radius: CGFloat(20), startAngle: CGFloat(0), endAngle: CGFloat(Double.pi * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath

如何创建这样一个圆的运动动画?

我已经在imageView上完成了移动动画,您可以在任何视图上尝试它

  private func animate(_ image: UIImageView) {
        
        UIView.animate(withDuration: 1, delay: 0, options: .curveLinear, animations: {
            image.transform = CGAffineTransform(translationX: self.view.frame.width/2-10, y: 0)
        }) { (success: Bool) in
            image.transform = CGAffineTransform.identity
            self.animate(image) // imageAnime is outlet
            self.imageAnim.layer.removeAllAnimations() // if you want to remove animation after its done animating once
        }
    }

在你希望动画完成的地方调用此函数

你想要什么样的“运动”?就像这里的红色矩形:那篇教程告诉了你如何做。老实说,我不明白它是如何工作的,如果我实现了它,我会看到很多错误。真的谢谢你,伙计!