ClippingBezier icon indicating copy to clipboard operation
ClippingBezier copied to clipboard

Using UIBezierPath(roundedRect: cornerRadius:) doesn't work as expected

Open bluepixeltech opened this issue 2 years ago • 0 comments

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:

Simulator Screen Shot - iPhone 13 Pro Max - 2022-06-07 at 10 47 00

But if change one of the rectangles to:

let path1 = UIBezierPath(roundedRect: rect1, cornerRadius: 30) The result will be:

Simulator Screen Shot - iPhone 13 Pro Max - 2022-06-07 at 10 47 22

It seems that rect1 is totally ignored.

Any help would be greatly appreciated :)

bluepixeltech avatar Jun 07 '22 15:06 bluepixeltech