UIView对下面的所有视图都不透明 [英] UIView not transparent to all views underneath

查看:84
本文介绍了UIView对下面的所有视图都不透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS应用程序,但遇到以下问题:我有一个 UIView ,其背景色的 alpha = 0.8 ,但我不希望它对它下面的所有元素透明。我通过在其 Draw(CGRect rect)方法中添加以下代码来使其透明:

I am working on an iOS application and I am having the following problem: I have a UIView which background color has alpha = 0.8, but I do not want it to be see-through for all elements underneath it. I am making it transparent by adding the following code to its Draw(CGRect rect) method:

var gctx = UIGraphics.GetCurrentContext();
gctx.AddEllipseInRect(new CGRect(rect.Location, rect.Size));
gctx.SetFillColor(UIColor.FromRGB(255, 255, 255).ColorWithAlpha(0.8f).CGColor);

但是,这种方式对于所有 UIViews都是透明的。下图说明了我的意思:

However, in this way it is see-through for all of the UIViews underneath it. The following image is illustrating what I mean:

大圈子的 alpha = 0.8 ,而位于其下方的小字母的 alpha = 1 。我要实现的是小圆圈的一部分,在大圆圈后面是不可见的,而大圆圈具有 alpha = 0.2 以便对

The big circle has alpha = 0.8, while the small one, which is below it, has alpha = 1. What I want to achieve is the part of the small circle that is behind the big one to be invisible, while the big circle has alpha = 0.2 in order to be slightly transparent to the background gradient.

推荐答案

尝试对小圆圈使用gc剪辑功能。
您需要将大圆或倒圆设置为剪切路径并绘制圆。

Try to use gc clip feature for small circle. You need to set big circle or inverse of it as clip path and draw the circle.

https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference / CGContext /#// apple_ref / c / func / CGContextClip

这篇关于UIView对下面的所有视图都不透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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