Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
[iOS][ReactNative v0.19.0]自定义视图具有意外的黑色背景_Ios_React Native - Fatal编程技术网

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

[iOS][ReactNative v0.19.0]自定义视图具有意外的黑色背景,ios,react-native,Ios,React Native,我有一个自定义视图绘制彩色路径,在React Native 0.19之前运行良好 但在React Native 0.19上,似乎有一个默认的黑色背景,这使我无法使用半透明颜色 在React Native 0.19上看起来是这样的: 如果我不在整个矩形上绘制任何内容或半透明颜色,您将看到黑色层 - (void)drawRect:(CGRect)rect { [[UIColor colorWithWhite:0 alpha:0] setFill]; CGContextFillRec

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

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

在React Native 0.19上看起来是这样的:

如果我不在整个矩形上绘制任何内容或半透明颜色,您将看到黑色层

- (void)drawRect:(CGRect)rect
{
    [[UIColor colorWithWhite:0 alpha:0] setFill];
    CGContextFillRect(UIGraphicsGetCurrentContext(), rect);

    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(10, 10, 20, 20)];
    [[UIColor redColor] setFill];
    [path fill];
}
请帮我解决这个问题

  • 反应本机v0.19.0
  • 在iPhone 6s Plus(9.2)模拟器上运行

覆盖
-drawRect
执行自定义绘图时,通常需要将其不透明设置为否,或在
-initWithFrame:

- (instancetype)initWithFrame:(CGRect)frame
{
  if (self = [super initWithFrame:frame]) {
    [self setOpaque:NO];
    // or [self setBackgroundColor:[UIColor clearColor]];
  }
  return self;
}


顺便说一句,虽然我们看到它是黑色的,但它不是黑色的。这只是因为没有提供适当显示的颜色,因为您覆盖了
-drawRect
,您负责与绘图相关的逻辑,但您没有按照预期处理此区域。

删除[[uicolorWithWhite:0 alpha:0]setFill];不,它不起作用,它是透明的,请注意alpha为0。您可以使用此CGContextRef context=UIGraphicsGetCurrentContext();CGContextFillPath(上下文);UIBezierPath*path=[UIBezierPath bezierPathWithRect:CGRectMake(10,10,20,20)];[[UIColor redColor]setFill];[路径填充];这很有效,谢谢你!但我不明白为什么它在RN 0.19之前工作?@xinthink据我所知,它应该和往常一样,可能是一些代码更改导致了这个问题,而这个问题没有在我们的项目中公开?对不起,我是说React Native v0.19.0 for RN。因此,在v0.19版本之前,应该是React native为我绘制颜色。谢谢@Kjuly@xinthink是的,可能是,不完全确定。