如何实现动态UIView屏蔽? [英] How to achieve dynamic UIView masking?
问题描述
我正在尝试实现一种动态的UIView屏蔽效果。这是一个草图:
I'm trying to achieve a sort of dynamic UIView masking effect. Here is a sketch:
正如您所看到的,我正在尝试创建一个可以有效地切割图像以显示其背后图像的UIView。我已经知道如何静态地返回带有蒙版的图像,但我希望揭示者可以拖动(我会使用平移手势)并且活着。
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).
推荐答案
屏蔽图像并不困难。
此链接显示基础知识。
http://iosdevelopertips.com/cocoa/how- to-mask-an-image.html
This link shows the basics. http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
但我个人认为我会制作2个UIImage视图并裁剪可拖动UIView的内容。我不确定,但是我希望剪辑和平移第二张图像的计算成本会低于应用蒙版,并且会让你获得更好的帧速率。
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.
所以我会这样做:UIImageView的完整图像。一个UIView在它上面有一个白色和一些透明度设置使它看起来是白色,然后一个UIImageView与图像放置或裁剪,以便只显示正确的部分。
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.
这篇关于如何实现动态UIView屏蔽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!