iOS swipe filters over static image

2019-09-06 16:20发布

问题:

I'm looking for a way to swipe image filters over top of a still image.

Mainly the base image stays in place, and the filters slide in over top when you swipe left or right.

Right now I have a base UIImageView and a Collection View over top of it which in theory would hold the filters (texture and gradient images).

I've read that UIImageViews and UIViews can't be live composited on top of each other, and that you must make the image before displaying it. So I can pre-make the image beforehand in code, then can I wipe-reveal the filter image to get the same effect? Using masks?

Code examples are nice, but a high level description on how to approach this would be helpful.

The app Spark has this functionality for videos, I'm looking to do something similar for photos.

回答1:

So I can pre-make the image beforehand in code, then can I wipe-reveal the filter image to get the same effect? Using masks?

Yes, but no need for a mask. Pre-make the filtered image and put it in an image view. Let's say this filtered effect is to be swiped in from the left. Then make the image view's content mode be Left, and put it at the left of the real image, with width zero. As the swipe happens, animate the width of the image view to the width of the image. This will cause the filtered image to be revealed from the left side.