iOS-从底部填充UIBezierPath的动画 [英] iOS - Fill Animation of a UIBezierPath from bottom

查看:392
本文介绍了iOS-从底部填充UIBezierPath的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义 UIView draw() UIBezierPath $ c>。我想填充该路径,可以说是一个从下到上的矩形。我该如何实现。

I have a UIBezierPath inside custom UIView, draw(). I want to fill that path, lets say a rectangle from bottom to top. How can I implement this.

来自这里我已经看到可以使用 CAShapeLayer 。动画效果很好,但是填充不会在矩形的底部到顶部进行。

From Here I have seen using CAShapeLayer its possible. That is working fine with animation but filling is not happening from bottom to top on the rectangle. Please guide.

推荐答案

这是您要的吗?

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")
}

这篇关于iOS-从底部填充UIBezierPath的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆