从 ccore 动画中的形状中删除黑色填充颜色
Remove black filled color from shape in ccore animation
我正在制作一个动画,其中图像在曲线路径中随线移动。我能够画线并移动飞机,但我在路径中得到了一个黑色填充部分。我该如何删除它?请在这里查看
以下是我创建动画的代码:
func animate(image: UIView, fromPoint start: CGPoint, toPoint end: CGPoint) {
// The animation
let animation = CAKeyframeAnimation(keyPath: "strokeEnd")
// Animation's path
let path = UIBezierPath()
// Move the "cursor" to the start
path.move(to: start)
path.addLine(to: start)
// Calculate the control points
let c1 = CGPoint(x: end.x - 30, y: start.y)
let c2 = CGPoint(x: end.x, y: start.y - 30)
// Draw a curve towards the end, using control points
path.addCurve(to: end, controlPoint1: c1, controlPoint2: c2)
// Use this path as the animation's path (casted to CGPath)
animation.path = path.cgPath
// The other animations properties
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
animation.duration = 3.0
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
// Apply it
image.layer.add(animation, forKey: "position")
let shapeLayer = CAShapeLayer()
shapeLayer.strokeColor = R.color.MyPurple()?.cgColor
shapeLayer.lineWidth = 3
shapeLayer.path = path.cgPath
self.view.layer.addSublayer(shapeLayer)
}
请添加以下行:
shapeLayer.fillColor = UIColor.clear.cgColor
我正在制作一个动画,其中图像在曲线路径中随线移动。我能够画线并移动飞机,但我在路径中得到了一个黑色填充部分。我该如何删除它?请在这里查看
以下是我创建动画的代码:
func animate(image: UIView, fromPoint start: CGPoint, toPoint end: CGPoint) {
// The animation
let animation = CAKeyframeAnimation(keyPath: "strokeEnd")
// Animation's path
let path = UIBezierPath()
// Move the "cursor" to the start
path.move(to: start)
path.addLine(to: start)
// Calculate the control points
let c1 = CGPoint(x: end.x - 30, y: start.y)
let c2 = CGPoint(x: end.x, y: start.y - 30)
// Draw a curve towards the end, using control points
path.addCurve(to: end, controlPoint1: c1, controlPoint2: c2)
// Use this path as the animation's path (casted to CGPath)
animation.path = path.cgPath
// The other animations properties
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
animation.duration = 3.0
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
// Apply it
image.layer.add(animation, forKey: "position")
let shapeLayer = CAShapeLayer()
shapeLayer.strokeColor = R.color.MyPurple()?.cgColor
shapeLayer.lineWidth = 3
shapeLayer.path = path.cgPath
self.view.layer.addSublayer(shapeLayer)
}
请添加以下行:
shapeLayer.fillColor = UIColor.clear.cgColor