Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bluepixeltech opened this issue Jun 7, 2022 · 0 comments

Comments

@bluepixeltech
Copy link

bluepixeltech commented Jun 7, 2022

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant