斯威夫特在使用一个动画块在动画CAShapeLayer strokeEnd [英] animating strokeEnd in a CAShapeLayer using an animation block in Swift

查看:316
本文介绍了斯威夫特在使用一个动画块在动画CAShapeLayer strokeEnd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图描绘出我已经到位成CAShapeLayer路径的形状。在此功能中,点阵列中的点重新present正多边形的顶点。动画没有发生,虽然。它只是出现,完全动画。

I am attempting to trace out the shape of a path that I've place into a CAShapeLayer. In this function, the points in the points array represent the vertices of a regular polygon. The animation isn't happening, though. It's just appearing, totally animated.

下面是code:

private func drawShape (point: [(x: Double, y:Double)]) {

    let shapeLayer = CAShapeLayer()

    let shapePath = UIBezierPath()
    shapePath.moveToPoint(CGPoint(x:point[point.count-1].x, y:point[point.count-1].y))

    for i in point {
        shapePath.addLineToPoint(CGPoint(x:i.x, y:i.y))
    }

    shapeLayer.path = shapePath.CGPath

    drawingSurface.layer.addSublayer(shapeLayer)

    shapeLayer.fillColor = UIColor.clearColor().CGColor
    shapeLayer.strokeColor = UIColor.blackColor().CGColor
    shapeLayer.strokeEnd = 0

    UIView.animateWithDuration(30, delay: 0, options: .CurveEaseInOut, animations: {
        shapeLayer.strokeEnd = 1
        }, completion: {finished in println("This Finished")
    })
}

我想到的是,它会笼络我已经设置(30秒的时刻)的时间行程,但相反,它只是似乎,没有动画绘制完全

What I expect is that it will draw the stroke over the duration that I have set (30 seconds at the moment), but instead, it just appears, fully drawn with no animation.

有什么想法?

推荐答案

我相信你已经找到了答案,但是从我的理解是,animateWithDuration方法只能大概动画8种不同的属性和EndAngle不是一天他们。只有CAAnimations可以做到这一点。 animateWithDuration和CAAnimations是专门为不同的事情。

I'm sure you already found the answer but from what I understand is that the animateWithDuration method can only animate about 8 different properties and the EndAngle is not one of them. Only CAAnimations can do this. animateWithDuration and CAAnimations are built for different things.

从IOS文件引用:

UIView类的以下属性动画:

The following properties of the UIView class are animatable:

@property帧

@property frame

@property边界

@property bounds

@property中心

@property center

@property变换

@property transform

@property阿尔法

@property alpha

@property的backgroundColor

@property backgroundColor

@property contentStretch

@property contentStretch

这篇关于斯威夫特在使用一个动画块在动画CAShapeLayer strokeEnd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆