user339946
user339946

Reputation: 6119

How to achieve dynamic UIView masking?

I'm trying to achieve a sort of dynamic UIView masking effect. Here is a sketch: enter image description here

So as you can see, I'm trying to create a UIView that can effectively cut through an image to reveal the image behind it. I already know how to return an image with a mask statically, however I would like the "revealer" to be draggable (I'll use pan gesture) and live.

Does anyone have any ideas or starting points on how to achieve this? Thanks

(NOTE: My demo says White layer, but I'd actually like to show another image or photo).

Upvotes: 5

Views: 1520

Answers (1)

madmik3
madmik3

Reputation: 6973

masking an image is not that difficult.

This link shows the basics. http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html

But personally I think i would make 2 UIImage views and crop the content of the draggable UIView. I'm not sure but I would expect that clipping and panning the second image will be less computationally expensive then applying the mask and will get you a better frame rate.

So I would do: UIImageView of the full image. A UIView on top of it with a white and some transparency setting to make it look white, then a UIImageView with the image either places or cropped so that only the correct section is showing.

Upvotes: 3

Related Questions