[英]iOS/Swift: How to make a blend of multiple UIViews
我正在嘗試將圖像與其他 UIView(CollectionView、背景 ImageView 等)進行顏色減淡混合。 在 Android 中,當我在畫布上繪制位圖時,我可以將一些視圖放在其他視圖上,然后將BlendMode.COLOR_DODGE
或PorterDuffXfermode(PorterDuff.Mode.ADD)
應用於 Paint。
我嘗試使用相同的類比來完成這項工作:將 UIView 放在其他視圖上並應用顏色減淡。 我已經嘗試過:
override func draw(_ rect: CGRect) {
self.image?.draw(in: rect, blendMode: .colorDodge, alpha: 1.0)
}
但是我注意到 blendMode 只有在我在它的 draw 方法中繪制視圖的所有內容時才有效,並且這種行為對我不起作用。
有什么方法可以在 iOS 中實現多個視圖的混合?
您可以使用compositingFilter
:
view.layer.compositingFilter = "colorDodgeBlendMode"
其他一些有效值:
“normalBlendMode” “darkenBlendMode” “multiplyBlendMode” “colorBurnBlendMode” “lightenBlendMode” “screenBlendMode” “colorDodgeBlendMode” “overlayBlendMode” “softLightBlendMode” “hardLightBlendMode” “differenceBlendMode” “exclusionBlendMode”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.