如何使 UIImageView 的一部分透明以在下面的图层中显示视图 [英] How to make a portion of an UIImageView transparent in order to show views in layers below
问题描述
这是一张照片解释,可以更好地说明我的意思:
Here is a photo explanation to better illustrate what I mean:
我有两个 UIImageViews
,View1
位于底部,View2
位于顶部:
I have two UIImageViews
, with View1
being on the bottom and View2
at the top:
我想做的是以编程方式在 View2
上设置一个完全透明的区域(即具有 0
的 alpha
),所以这将是最终结果:
What I would like to do accomplish is to programmatically set an area on View2
that is completely transparent (i.e. has an alpha
of 0
), so that this will be the end result:
我没有找到与以形状(特别是圆形)的形式将 UIImageView 的一部分标记为透明相关的类似问题,并且想知道我应该如何解决这个问题?
I haven't been able to find a similar problem related to marking a part of a UIImageView transparent in the form of a shape (specifically, a circle), and was wondering how I should tackle this problem?
谢谢!
推荐答案
你可以走的一条路是 CoreGraphics:
One road you could go is CoreGraphics:
- 创建图像上下文
- 设置你需要的剪切路径(或者只是在绘制后清除洞"的圆圈)
- 将原始图像绘制到上下文中
- 根据该上下文制作 UIImage
- 将图像分配给顶部的 UIImageView
这篇关于如何使 UIImageView 的一部分透明以在下面的图层中显示视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!