ios swift中的形状

问题描述

如何绘制背景模糊的曲线?

enter image description here

在这里我附上了我的代码,但没有得到确切的输出

@IBDesignable class CurvedHeaderView: UIView {
@IBInspectable var curveHeight:CGFloat = 50.0
var curvedLayer = CAShapeLayer()
override func draw(_ rect: CGRect) {
    let path = UIBezierPath()
    path.move(to: CGPoint(x: 0,y: 0))
    path.move(to: CGPoint(x: 0,y: rect.height))
    //        path.addLine(to: CGPoint(x: 0,y: 0))
    path.addLine(to: CGPoint(x: rect.width,y: rect.height))
    path.addArc(withCenter: CGPoint(x: CGFloat(rect.width) - curveHeight,y: 100),radius: curveHeight,startAngle: 0,endAngle: 1.5 * CGFloat.pi,clockwise: false)
    //        path.addArc(withCenter: CGPoint(x: CGFloat(rect.width) - curveHeight,y: rect.height),clockwise: false)
    //        path.addLine(to: CGPoint(x: curveHeight,y: rect.height - curveHeight))
    
    //        path.addLine(to: CGPoint(x: curveHeight,y: 50))
    path.addLine(to: CGPoint(x: curveHeight,y: curveHeight))
    path.addArc(withCenter: CGPoint(x: curveHeight,y: 0),endAngle:  CGFloat.pi,clockwise: true)
    
    path.addLine(to: CGPoint(x: 0,y: 0))
    //        path.addArc(withCenter: CGPoint(x: curveHeight,y: rect.height - (curveHeight * 2.0)),clockwise: true)
    path.close()
    curvedLayer.path = path.cgPath
    curvedLayer.fillColor = UIColor.white.cgColor
    curvedLayer.frame = rect
    self.layer.insertSublayer(curvedLayer,at: 0)
    self.layer.shadowColor = UIColor.black.cgColor
    self.layer.shadowRadius = 10.0
    self.layer.shadowOpacity = 0.7
}

}

如果有任何错误,请分享给我参考

提前致谢

解决方法

我已经尝试过,但它显示代码可以工作,但没有完全得到

  @IBOutlet weak var blurEffectView: UIVisualEffectView!
        override func viewDidLayoutSubviews() {
           let maskView = CurvedHeaderView(frame: blurEffectView.bounds)
            maskView.clipsToBounds = true;
            maskView.backgroundColor = UIColor.clear
            blurEffectView.mask = maskView
        }