【问题标题】:UIView not transparent to all views underneathUIView 对下面的所有视图都不透明
【发布时间】:2017-01-12 07:44:52
【问题描述】:

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

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

但是,通过这种方式,它下面的所有UIViews 都是透明的。下图说明了我的意思:

大圆圈有alpha = 0.8,而它下面的小圆圈有alpha = 1。我想要实现的是大圆后面的小圆圈部分不可见,而大圆圈有alpha = 0.2以便对背景渐变稍微透明。

【问题讨论】:

    标签: ios uiview transparency alpha


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-09-01
      • 2011-01-21
      • 2019-03-19
      • 2012-02-29
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 2015-02-17
      • 2021-01-19
      相关资源
      最近更新 更多