【发布时间】:2015-12-09 13:23:32
【问题描述】:
我正在修改 IOS 应用程序以允许额外的背景层。所有现有的叠加层都是UIImageViews,处理transparency就好了。
现有背景主要是UIView。我想将黑色背景更改为transparent,以便在后面放置另一个视图。它不起作用。最简单但无法正常工作的代码如下:
# import "TestUIView.h"
@implementation TestUIView
- (void)drawRect:(CGRect)rect {
self.opaque = NO;
[self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 0,0,0,0);
CGContextFillRect(context, rect);
// and here goes my code where I draw to the transparent background
}
@end
执行此操作时,会生成一个黑色矩形。我已将其背景设置为透明并用透明填充其前景。我需要做什么才能获得一个UIView,以便我可以在透明背景上进行绘制?
(而且我知道我可以更改整个视图的 alpha,这不是问题。我想要在真正透明的背景上进行不透明绘图)。
更新:它不在 setbackgroundcolor 中,我很欣赏它没有必要,所以不应该在那里,但如果它被注释掉,也会发生同样的事情。我不能在透明背景上画画;上面的代码显示我什至不能制作一个透明的矩形来绘制。
谢谢
【问题讨论】:
-
试试 yourview.backgroundColor = [[UIColor blackColor] colorWithComponent:0.5];
-
如果 alpha 为 0,您将什么也看不到。那你期待什么?
-
默认 opaue 为 NO。
标签: ios objective-c uiview drawrect