【问题标题】:iOS - Fill Animation of a UIBezierPath from bottomiOS - 从底部填充 UIBezierPath 的动画
【发布时间】:2017-05-18 18:15:23
【问题描述】:

我在自定义UIViewdraw() 中有一个UIBezierPath。我想填充那条路径,让我们说一个从下到上的矩形。我该如何实现。

来自Here 我已经看到使用CAShapeLayer 是可能的。这适用于动画,但填充不会从矩形的底部到顶部发生。请指导。

【问题讨论】:

    标签: ios animation uiview swift3 core-graphics


    【解决方案1】:

    这是你要求的吗?

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

    【讨论】:

    • 感谢您的解决方案。当 endPath 不是矩形而是梯形时,我如何实现它。我尝试使用 addLines,但填充方向与预期不符。你知道是否有可能得到解决方法。再次感谢。
    • 谢谢! ,它解决了我的问题。你真是太棒了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多