美文网首页
ios给整个屏幕加遮罩

ios给整个屏幕加遮罩

作者: pomelo_西 | 来源:发表于2019-03-26 16:43 被阅读0次
    // 绘制遮罩,定义宽高为屏幕的宽高
    let maskView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
    // 设置透明度
     maskView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
    // 添加点击事件,点击自身,移除
    maskView.addTarget(self, action: #selector(hideMask))
    // 给遮罩上添加一些内容
    let logoutView = UIView(frame: CGRect(x: 0, y: self.view.frame.height - 80, width: self.view.frame.width, height: 80))
    maskView.addSubview(logoutView)
    logoutView.backgroundColor = UIColor.white
    logoutView.layer.cornerRadius = 10
    logoutView.layer.masksToBounds = true
    // 将遮罩添加到屏幕上
    UIApplication.shared.keyWindow?.addSubview(maskView)
    
    // 移除遮罩事件
    @objc func hideMask(uiTap: UITapGestureRecognizer) {
        let view = uiTap.view
        view?.removeFromSuperview()
    }
    

    相关文章

      网友评论

          本文标题:ios给整个屏幕加遮罩

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