简体   繁体   中英

Animation with Swift

I want to hav this kind of animation in my app, a case where an arrow shape such that when clicked it transforms into a mark.

This is what i have at present using the code below

目前的工作

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

}

the flow is illustrated in the images bellow

On click of this image 箭头图标

It transform to this image 标记图标

我无法解决,我用动画切换了图像

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM