我有一个UIBezierPath
内部定制UIView
, draw()
。我想填充该路径,假设从下到上是一个矩形。我怎样才能实现这个。
From Here http://jamesonquave.com/blog/fun-with-cashapelayer/我见过使用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")
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)