Swift 的动画

Animation with Swift

我想在我的应用程序中使用这种动画,在这种情况下,箭头的形状在单击时会变成一个标记。

这是我目前使用下面的代码得到的

func handleTransform(){

    let arrowPath = UIBezierPath()
    arrowPath.move(to: CGPoint(x: 50, y: 0))
    arrowPath.addLine(to: CGPoint(x: 25, y: 75))
    arrowPath.addLine(to: CGPoint(x: 25, y: 75))
    arrowPath.addLine(to: CGPoint(x: 25, y: 45))
    arrowPath.addLine(to: CGPoint(x: 25, y: 35))
    arrowPath.close()

    let progressLines = CAShapeLayer()
    progressLines.path = arrowPath.cgPath
    progressLines.strokeColor = UIColor.black.cgColor
    progressLines.fillColor = UIColor.clear.cgColor
    progressLines.lineWidth = 10.0
    progressLines.lineCap = kCALineCapRound

    self.view.layer.addSublayer(progressLines)

    let animateStrokeEnd = CABasicAnimation(keyPath: "strokeEnd")
    animateStrokeEnd.duration = 3.0
    animateStrokeEnd.fromValue = 0.0
    animateStrokeEnd.toValue = 1.0

    progressLines.add(animateStrokeEnd, forKey: "animate stroke end animation")

}

流程如下图所示

点击这张图片

变成这张图

我已经解决了,我做了一个带动画的切换图