Draw hole on UIBlurEffect

前端 未结 3 2102
一整个雨季
一整个雨季 2021-02-08 17:48

Xcode 8.0 - Swift 2.3
I have an internal extension to create blur layer that works great:

internal extension UIView {
    
    /**
     Add         


        
3条回答
  •  清歌不尽
    2021-02-08 18:07

    I've had the same issue in my code. After I applied the mask on the UIView containing UIVisualEffectView, the blur disappeared. However, I could turn it back by overriding the draw method on the parent:

    override func draw(_ rect: CGRect) {
        super.draw(rect)
    }
    

    I don't know why it works exactly, but hope it will help someone. The code I used to cut the hole out:

    private func makeViewFinderMask() -> CAShapeLayer {
    
        let path = UIBezierPath(rect: bounds)
        let croppedPath = UIBezierPath(roundedRect: viewFinderBounds(), cornerRadius: viewFinderRadius)
        path.append(croppedPath)
        path.usesEvenOddFillRule = true
    
        let mask = CAShapeLayer()
        mask.path = path.cgPath
        mask.fillRule = kCAFillRuleEvenOdd
        return mask
    }
    

提交回复
热议问题