iOS 开发 swift 抠图

作者: littleGG 发布时间: 2019-08-08 浏览: 217 次 编辑
 func addTransparencyView(with tempPath: UIBezierPath?) -> CAShapeLayer? {
        let path = UIBezierPath(rect: UIScreen.main.bounds)
        if let aPath = tempPath {
            path.append(aPath)
        }
        path.append(tempPath1)
        path.usesEvenOddFillRule = true
        
        let shapeLayer = CAShapeLayer()
        shapeLayer.path = path.cgPath
        shapeLayer.fillColor = UIColor.black.cgColor //其他颜色都可以,只要不是透明的
        shapeLayer.fillRule = .evenOdd
        return shapeLayer
    }
   
    var tempPath = UIBezierPath(roundedRect: CGRect(x: 120, y: 150, width: 100, height: 50), byRoundingCorners: [.topLeft, .topRight, .bottomRight, .bottomLeft], cornerRadii: CGSize(width: 4, height: 4))
var guideView = UIView(frame: UIScreen.main.bounds)
guideView.backgroundColor = UIColor.black
guideView.alpha = 0.6
guideView.layer.mask = addTransparencyView(with: tempPath)
UIApplication.shared.keyWindow?.addSubview(guideView)