iOS - 从底部填充 UIBezierPath 的动画
<p><p>我在自定义 <code>UIView</code> 中有一个 <code>UIBezierPath</code>,<code>draw()</code>。我想填充那条路径,假设是一个从下到上的矩形。我该如何实现。</p>
<p>来自 <a href="http://jamesonquave.com/blog/fun-with-cashapelayer/" rel="noreferrer noopener nofollow">Here</a>我已经看到使用 <code>CAShapeLayer</code> 是可行的。这对于动画效果很好,但填充不是从矩形的底部到顶部发生的。请指导。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是你要的吗?</p>
<pre><code>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")
}
</code></pre></p>
<p style="font-size: 20px;">关于iOS - 从底部填充 UIBezierPath 的动画,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41464101/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41464101/
</a>
</p>
页:
[1]