gpt4 book ai didi

ios - 使用 Swift 中的动画 block 在 CAShapeLayer 中为 strokeEnd 设置动画

转载 作者:可可西里 更新时间:2023-11-01 00:37:52 24 4
gpt4 key购买 nike

我试图描绘出我放置到 CAShapeLayer 中的路径的形状。在此函数中,points 数组中的点表示正多边形的顶点。但是,动画没有发生。它刚刚出现,完全生动。

代码如下:

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 秒)绘制笔画,但相反,它只是出现,完全绘制,没有动画。

有什么想法吗?

最佳答案

我相信您已经找到了答案,但据我了解,animateWithDuration 方法只能为大约 8 个不同的属性设置动画,而 EndAngle 不是其中之一。只有 CAAnimations 可以做到这一点。 animateWithDuration 和 CAAnimations 是为不同的事物构建的。

引用自 ios 文档:

The following properties of the UIView class are animatable:

@property frame

@property bounds

@property center

@property transform

@property alpha

@property backgroundColor

@property contentStretch

关于ios - 使用 Swift 中的动画 block 在 CAShapeLayer 中为 strokeEnd 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28784108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com