我正在尝试将图像与其他 UIView(CollectionView、背景 ImageView,...)进行颜色减淡混合。在 Android 中,我可以将一些 View 置于其他 View 之上,然后在绘制位图时将 BlendMode.COLOR_DODGE
或 PorterDuffXfermode(PorterDuff.Mode.ADD)
应用于 Paint在 Canvas 上。
我尝试使用相同的类比来完成这项工作:将 UIView 放在其他 View 上并应用颜色减淡。我已经尝试过了:
override func draw(_ rect: CGRect) {
self.image?.draw(in: rect, blendMode: .colorDodge, alpha: 1.0)
}
但我注意到,只有当我在其绘制方法内绘制 View 的所有内容时,blendMode 才有效,并且该行为对我不起作用。
iOS 有没有办法实现多个 View 的混合?
最佳答案
您可以使用compositingFilter
:
view.layer.compositingFilter = "colorDodgeBlendMode"
其他一些有效值:
"normalBlendMode" "darkenBlendMode" "multiplyBlendMode" "colorBurnBlendMode" "lightenBlendMode" "screenBlendMode" "colorDodgeBlendMode" "overlayBlendMode" "softLightBlendMode" "hardLightBlendMode" "differenceBlendMode" "exclusionBlendMode"
关于iOS/swift : How to make a blend of multiple UIViews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60549638/