如何解决ios swift中的形状
如何绘制背景模糊的曲线?
在这里我附上了我的代码,但没有得到确切的输出
@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
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。