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]
}
网友评论