美文网首页
iOS 引导页挖空透明

iOS 引导页挖空透明

作者: 秋叶红90 | 来源:发表于2020-11-19 23:31 被阅读0次
  1. 使用CAShapeLayer 然后使用UIBezierPath 换线条填充颜色黑色
let maskLayer = CAShapeLayer()
    func configMask(rect:CGRect) {
        let fromPath = maskLayer.path

        maskLayer.fillColor = UIColor.black.cgColor
        var radius:CGFloat = 5
        let frame = rect
        radius = min(radius, min(frame.width / 2.0, frame.height / 2.0))
        let highlightedPath = UIBezierPath(roundedRect: frame, cornerRadius: radius)
        let toPath = UIBezierPath(rect: bgView.bounds)
        toPath.append(highlightedPath)
        maskLayer.path = toPath.cgPath

     ///  CAShapeLayerFillRule.evenOdd 交叉挖空 另外一个是填充
        maskLayer.fillRule = CAShapeLayerFillRule.evenOdd
        bgView.layer.mask = maskLayer
        
        let animation = CABasicAnimation(keyPath: "path")
        animation.duration = 1
        animation.fromValue = fromPath
        animation.toValue = toPath
        maskLayer.add(animation, forKey: nil)
    }

2 使用方法

  1. 添加属性
@IBOutlet weak var bgMM: UIButton!
    var bgView:TEEESAVie3w = Bundle.main.loadNibNamed("TEEESAVie3w", owner: nil, options: nil)!.first! as! TEEESAVie3w
override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
//        let rect = CGRect.init(x: 0, y: 100.0, width: 100, height: 100)
//
        bgView.frame = self.view.bounds
        self.view.addSubview(bgView)
        
        let rect =  self.view.convert(self.bgMM.frame, from: self.bgMM.superview)
        self.configMask(rect: rect)
        
        self.view.backgroundColor = UIColor.red
    }

效果如下

Simulator Screen Shot - iPhone 12 mini - 2020-11-19 at 23.27.33.png

相关文章

  • iOS 引导页挖空透明

    使用CAShapeLayer 然后使用UIBezierPath 换线条填充颜色黑色 2 使用方法 添加属性 效果如下

  • ios引导页

    首先修改 App Transport Security SettingsAllow Arbitrary Loads...

  • iOS 引导页

    在AppDelegate.m中:我们需要两个Viewcongtroller来实现;myViewController...

  • ios 引导页

    目标功能 能够快速实现普通引导页功能. 提供自定义view的加载模式. 提供特定样式的加载模式,只需要配置即可. ...

  • iOS引导页

    在我们项目中经常会用到引导页,引导页主要功能就是向用户展示你的产品。 这是我写的一个例子的效果图(图片是随便找的):

  • iOS引导页

    引导页是App中的基本功能,指导用户理解某些操作或版本变化等等。 引导页可能出现在任何时候,页面内容会根据可交互度...

  • iOS引导页、启动页

    前言 这里使用 launchScreen 、.storyboard 文件创建启动图和引导页。首次打开项目或者更新后...

  • iOS 引导页适配

    1,图片适配,最早以前是自己命名规范,例如@1x,@2x,@3x等,3套图基本上就够用了 2,在iPhone X之...

  • ios开发,引导页

    在viewController.m里面 @interface ViewController () { UISc...

  • iOS 引导页 --LaunchIntroduction

    一、前言 引导页,一个酷炫的页面,基本上每个应用程序刚安装后启动的时候都会有一个引导页,用于引导用户使用APP,怎...

网友评论

      本文标题:iOS 引导页挖空透明

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