如何使 UIImageView 的一部分透明以在下面的图层中显示视图 [英] How to make a portion of an UIImageView transparent in order to show views in layers below

查看:40
本文介绍了如何使 UIImageView 的一部分透明以在下面的图层中显示视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一张照片解释,可以更好地说明我的意思:

Here is a photo explanation to better illustrate what I mean:

我有两个 UIImageViewsView1 位于底部,View2 位于顶部:

I have two UIImageViews, with View1 being on the bottom and View2 at the top:

我想做的是以编程方式在 View2 上设置一个完全透明的区域(即具有 0alpha),所以这将是最终结果:

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:

  1. 创建图像上下文
  2. 设置你需要的剪切路径(或者只是在绘制后清除洞"的圆圈)
  3. 将原始图像绘制到上下文中
  4. 根据该上下文制作 UIImage
  5. 将图像分配给顶部的 UIImageView

https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/HandlingImages/Images.html#//apple_ref/doc/uid/TP40010156-CH13-SW1

这篇关于如何使 UIImageView 的一部分透明以在下面的图层中显示视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆