[iOS] [ReactNative v0.19.0]自定义视图具有意外的黑色背景

时间:2016-01-31 06:30:26

标签: ios react-native

我有一个自定义视图绘制彩色路径,在React Native 0.19之前运行良好

但是在React Native 0.19上,似乎有一个默认的黑色背景,这使我无法使用半透明的颜色。

在React Native 0.19上看起来像这样:

enter image description here

如果我在整个矩形上没有画任何颜色或半透明颜色,你会看到黑色图层

qml: started animation at 2016-01-31T06:29:31.209Z
qml: finished animation at 2016-01-31T06:29:34.631Z

请帮我解决这个问题。

  • React Native v0.19.0
  • 在iPhone 6s Plus(9.2)模拟器上运行

1 个答案:

答案 0 :(得分:2)

当您覆盖-drawRect以执行自定义绘图时,您需要将其不透明设置为NO或在-initWithFrame:中手动设置其背景颜色

- (instancetype)initWithFrame:(CGRect)frame
{
  if (self = [super initWithFrame:frame]) {
    [self setOpaque:NO];
    // or [self setBackgroundColor:[UIColor clearColor]];
  }
  return self;
}
不过,虽然我们看到黑色,但它并不是黑色的。这只是因为没有提供适当显示的颜色,因为你覆盖-drawRect,你负责绘图相关的逻辑,但你没有像预期的那样照顾这个区域。