Stacking UIViews with blend modes in iOS Stacking UIViews with blend modes in iOS xcode xcode

Stacking UIViews with blend modes in iOS


Unfortunately there is no way to do a non-composite blend between UIViews on iOS. UIKit doesn't provide the functionality, and you've already noted, CALayer can't do it either.

In general, implementing -drawRect in a UIView won't help you. You're drawing into an empty bitmap -- it doesn't contain the bits of the views behind it, since those might change at any time (any view or layer might be animated). CA fundamentally assumes that layers' contents should be independent of each other.

You could try, in your -drawRect:

  1. create an image context
  2. capture the views under your view using -[CALayer renderInContext:] for each
  3. create an image from the image context
  4. draw that image into your view
  5. set the blend mode and draw on top of that

But that will be slow and fragile, and won't work if you animate any of the views. I wouldn't recommend it.

If you really need to do this, you're going to have to switch your whole scene to render with OpenGL, where you've got more freedom.