>  Q&A  >  본문

ios - 如果对一个CALayer图层或者UIView视图中间镂空

一个背景黑色50%透明,中间镂空一个全透明的区域该怎么弄?

迷茫迷茫2721일 전840

모든 응답(3)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-04-17 13:38:48

    绘制View的时候用layer.mask给layer加个图片蒙版(可以做一张灰白图片,黑色显示,白色不显示,灰色代表半透明)。

    회신하다
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:38:48

    全透明的UIView上盖一层半透明的中间镂空的图片不就好了

    회신하다
    0
  • 阿神

    阿神2017-04-17 13:38:48

    let path = UIBezierPath(rect:self.view.bounds)

        path.appendPath(UIBezierPath(rect: CGRect(x: 100, y: 100, width: 200, height: 300)).bezierPathByReversingPath())
        let shape = CAShapeLayer()
        
        shape.path = path.CGPath
        
        blurView.layer.mask = shape

    회신하다
    0
  • 취소회신하다