UIView not transparent to all views underneath

不打扰是莪最后的温柔 提交于 2020-01-05 05:48:09

问题


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);

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

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.


回答1:


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



来源:https://stackoverflow.com/questions/39322095/uiview-not-transparent-to-all-views-underneath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!