【发布时间】:2017-05-18 18:15:23
【问题描述】:
我在自定义UIView、draw() 中有一个UIBezierPath。我想填充那条路径,让我们说一个从下到上的矩形。我该如何实现。
来自Here 我已经看到使用CAShapeLayer 是可能的。这适用于动画,但填充不会从矩形的底部到顶部发生。请指导。
【问题讨论】:
标签: ios animation uiview swift3 core-graphics
我在自定义UIView、draw() 中有一个UIBezierPath。我想填充那条路径,让我们说一个从下到上的矩形。我该如何实现。
来自Here 我已经看到使用CAShapeLayer 是可能的。这适用于动画,但填充不会从矩形的底部到顶部发生。请指导。
【问题讨论】:
标签: ios animation uiview swift3 core-graphics
这是你要求的吗?
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")
}
【讨论】: