Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 清除UIBezierPath和fill上的背景色_Ios_Swift_Core Graphics_Uibezierpath - Fatal编程技术网

Ios 清除UIBezierPath和fill上的背景色

Ios 清除UIBezierPath和fill上的背景色,ios,swift,core-graphics,uibezierpath,Ios,Swift,Core Graphics,Uibezierpath,我想要一个底部有曲线的视图 我创建了这个ArchView,除了一件事,那就是蓝色的部分,我希望它是透明的 如果我将背景色设置为。清除,则会发生以下情况: 这是拱形视图的代码: class ArchedView: UIView { let archHeight: CGFloat let bColor: UIColor let archColor: UIColor let contentView: UIView = UIView() init(archH

我想要一个底部有曲线的视图

我创建了这个
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()
有关,但我不明白这里发生了什么。

检查您的View.backgroundcolor@ReinierMelian我不确定我是否了解你,哪个视图。背景色?这是一个UIView,不是UIViewController。您的背景色是清晰的,
backgroundColor=.clear
为什么不使用遮罩层呢?