ClippingBezier
ClippingBezier copied to clipboard
Using UIBezierPath(roundedRect: cornerRadius:) doesn't work as expected
Hi,
Thank a so much for the awesome library. I have a problem which I am trying to get the union of two intersecting paths in Swift. One is a corner with rounded corners and the other one a regular rectangle. If use regular rectangles:
`
iv = UIImageView(image: UIImage(named: "dog"))
blurView = UIVisualEffectView(frame: view.bounds)
blurView.effect = UIBlurEffect(style: .light)
view.addSubview(iv)
view.addSubview(blurView)
iv.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
blurView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
let rect1 = CGRect(x: 100, y: 100, width: 200, height: 200)
let rect2 = CGRect(x: 150, y: 200, width: 200, height: 200)
let path0 = UIBezierPath(rect: blurView.bounds)
let path1 = UIBezierPath(rect: rect1)
let path2 = UIBezierPath(rect: rect2)
let unionPathArray = path1.union(with: path2)
let unionPath = UIBezierPath()
if let array = unionPathArray {
array.forEach(unionPath.append)
path0.append(unionPath.reversing())
let layerUnion = CAShapeLayer()
layerUnion.path = path0.cgPath
blurView.layer.mask = layerUnion
}
` I have a background image (UIImageView object) which is covered by a blurred view (UIVisualEffectView object). I am trying to exclude the union of the rect1 and rec2 from the blur view. The result is as following which CORRECT:
But if change one of the rectangles to:
let path1 = UIBezierPath(roundedRect: rect1, cornerRadius: 30)
The result will be:
It seems that rect1 is totally ignored.
Any help would be greatly appreciated :)