美文网首页
App置灰或则页面置灰

App置灰或则页面置灰

作者: 桃李不言的蹊 | 来源:发表于2022-12-13 14:17 被阅读0次

    1.页面或则view置灰的方式,如果是整个App置灰就设置view为window

    ///1.第一种是给view上添加一个置灰的view
        @objc private func addGrayViewOnTop(){
            let overlay = UIView.init(frame: stackView.bounds)
            overlay.translatesAutoresizingMaskIntoConstraints = false
            overlay.backgroundColor = .lightGray
            overlay.layer.compositingFilter = "saturationBlendMode"
            overlay.isUserInteractionEnabled = false
            stackView.addSubview(overlay)
    
        }
        
        ///2.用滤镜的方式  如果需要整个App置灰,就挂在Window上  需要哪里置灰挂在哪里
        @objc private func useFilterMethod(){
            let color = UIColor.lightGray
            var red: CGFloat = 0
            var green: CGFloat = 0
            var blue: CGFloat = 0
            var alpha: CGFloat = 0
            color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
            guard let filter = CIFilter.init(name: "colorMonochrome") else { return }
            filter.setValue([red, green, blue, alpha], forKey: "inputColor")
            filter.setValue(0, forKey: "inputBias")
            filter.setValue(1, forKey: "inputAmount")
            stackView.layer.filters = [filter]
        }
    

    相关文章

      网友评论

          本文标题:App置灰或则页面置灰

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