清除UIBezierPath上的背景色并填充

问题描述

我想查看底部有一条曲线。

我创建的ArchView可以完美地完成工作,除了一件事情,蓝色的部分我希望它是透明的。

enter image description here

如果我将背景色设置为.clear,则会发生以下情况:

enter image description here

这是ArchView代码

class ArchedView: UIView {
    let archHeight: CGFloat
    let bColor: UIColor
    let archColor: UIColor
    let contentView: UIView = UIView()

    init(archHeight: CGFloat,bColor: UIColor,archColor: UIColor) {
        self.archHeight = archHeight
        self.bColor = bColor
        self.archColor = archColor
        super.init(frame: .zero)
        backgroundColor = .clear
        addSubview(contentView)

        contentView.backgroundColor = bColor
        contentView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-archHeight)
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func draw(_ rect: CGRect) {
        let height: CGFloat = archHeight
        let ovalRect = CGRect(x: 0,y: 0,width: frame.width,height: height)
        let ovalPath = UIBezierPath()
        ovalPath.addArc(withCenter: CGPoint(x: 0,y: 0),radius: (ovalRect.width / 2) * 1.3,startAngle: 180 * .pi/180,endAngle: 0 * .pi/180,clockwise: false)
        ovalPath.addLine(to: CGPoint.zero)

        ovalPath.close()

        var ovalTransform = CGAffineTransform(translationX: ovalRect.midX,y: frame.height - height)
        ovalTransform = ovalTransform.scaledBy(x: 1,y: height / ovalPath.bounds.height)
        ovalPath.apply(ovalTransform)

        archColor.setFill()
        ovalPath.fill()
    }
}

我假设它与fill()有关,但是我不明白这里发生了什么。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)