问题
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