自动启动strokeEnd动画

时间:2017-05-11 10:47:41

标签: ios swift animation

我有一个画圆圈的动画。我结合了3个不同的圆形动画来创建一个程式化的图形/饼图。

他们在按钮的@IBAction中制作完美的动画。但是当Storyboard / ViewController打开/导航到?

时,我将如何自动启动动画?

动画代码如下:

    //NF Colour
    let colorNF = UIColor(red: 28/255, green: 117/255, blue: 189/255, alpha: 1)

    // Create Holding Rectangle and Start and End Angles
    let ovalStartAngleNF = CGFloat(-90.01 * .pi/180)
    let ovalEndAngleNF = CGFloat(10.0 * .pi/180)
    let ovalRectNF = CGRect(origin: CGPoint(x: 122.5,y: 83.5), size: CGSize(width: 100, height: 100))

    // Create Bezier Path
    let ovalPathNF = UIBezierPath()

    // Apply Attributes to Bezier Path
    ovalPathNF.addArc(withCenter: CGPoint(x: ovalRectNF.midX, y: ovalRectNF.midY),
                      radius: ovalRectNF.width / 2,
                      startAngle: ovalStartAngleNF,
                      endAngle: ovalEndAngleNF, clockwise: true)

    // Styling of the Curve
    let progressLineNF = CAShapeLayer()
    progressLineNF.path = ovalPathNF.cgPath
    progressLineNF.strokeColor = colorNF.cgColor
    progressLineNF.fillColor = UIColor.clear.cgColor
    progressLineNF.lineWidth = 20.0
    progressLineNF.lineCap = kCALineCapRound

    // Add Curve to Viewport
    self.view.layer.addSublayer(progressLineNF)

    // Animated the 'Stroke End' from 0 to 1 over 3 Seconds
    let animateStrokeEndNF = CABasicAnimation(keyPath: "strokeEnd")
    animateStrokeEndNF.duration = 3.0
    animateStrokeEndNF.fromValue = 0.0
    animateStrokeEndNF.toValue = 1.0

    // Add the Animation to the Progress Line
    progressLineNF.add(animateStrokeEndNF, forKey: "animate stroke end animation")

0 个答案:

没有答案