Saz*_*han 2 animation core-graphics uiview ios swift3
我有一个UIBezierPath内部自定义UIView, draw(). 我想填充那条路径,让我们说一个从底部到顶部的矩形。我该如何实现这一点。
从这里我看到了使用CAShapeLayer它的可能。这对动画效果很好,但在矩形上从下到上没有填充。请指导。
这是你要求的吗?
func zoom() {
let startPath = UIBezierPath(rect: CGRect(x: 0, y: self.frame.size.height-30, width: self.frame.size.width, height: 30))
let endPath = UIBezierPath(rect: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))
let rectangleLayer = CAShapeLayer()
rectangleLayer.path = startPath.cgPath
rectangleLayer.fillColor = UIColor.cyan.cgColor
self.layer.addSublayer(rectangleLayer)
let zoomAnimation = CABasicAnimation()
zoomAnimation.keyPath = "path"
zoomAnimation.duration = 2.0
zoomAnimation.toValue = endPath.cgPath
zoomAnimation.fillMode = kCAFillModeForwards
zoomAnimation.isRemovedOnCompletion = false
rectangleLayer.add(zoomAnimation, forKey: "zoom")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1574 次 |
| 最近记录: |