美文网首页
swift:项目功能引导

swift:项目功能引导

作者: 蛋哥是只猫 | 来源:发表于2020-03-24 17:24 被阅读0次

    项目中我们经常需要做一个简单的功能引导,本编主要记录一下我自己项目中写的一个简单的功能引导,下面是主要创建部分代码:

  // frame为镂空部分尺寸
  fileprivate func createMask(frame:CGRect){
    if tipsMask != nil {
      tipsMask.removeFromSuperlayer()
      tipsMask = nil
    }
    if self.borderLayer != nil {
      borderLayer.removeFromSuperlayer()
      self.borderLayer = nil
    }
    
    let path = UIBezierPath(rect: self.bounds)
    path.append(UIBezierPath(rect: frame).reversing()) // 反转路径形成镂空
    tipsMask = CAShapeLayer()
    tipsMask.path = path.cgPath
    self.layer.mask = tipsMask
    let borderFrame = CGRect(x: frame.origin.x - 4, y: frame.origin.y - 4, width: frame.width + 8, height: frame.height + 8)
    // 创建虚线边框
    borderLayer = CAShapeLayer()
    borderLayer.path = UIBezierPath(roundedRect: borderFrame, cornerRadius: 2).cgPath
    borderLayer.lineWidth = 1
    borderLayer.lineDashPattern = [4,4]
    borderLayer.fillColor = nil
    borderLayer.strokeColor = UIColor.white.cgColor
    self.layer.addSublayer(borderLayer)
  }
  

使用:

   let button = UIButton(type: .contactAdd)
    self.view.addSubview(button)
    button.frame = CGRect(x: 100, y: 100, width: 60, height: 60)
    let guidView = XGuidView(frame: UIScreen.main.bounds)
    let frame = self.view.convert(button.frame, to: self.view)
    guidView.createUI(rectangleFrames: [frame])
    self.view.addSubview(guidView)

git项目地址https://github.com/wangxiaobai1840/FunctionGuidanceDemo

相关文章

网友评论

      本文标题:swift:项目功能引导

      本文链接:https://www.haomeiwen.com/subject/nrcayhtx.html