【问题标题】:ios casting objc pointer to struct cgcolorrefios将objc指针转换为struct cgcolorref
【发布时间】:2012-05-15 08:54:17
【问题描述】:

我启用了ARC,我正在尝试这样做:

CGColorRef outerColor = (id)[UIColor colorWithWhite:1.0 alpha:1.0].CGColor;

我尝试的转换导致错误:

Implicit conversion of an Objective-C pointer to 'CGColorRef' (aka 'struct CGColor *') is disallowed with ARC

我尝试了很多东西,但我不知道如何完成这个演员表。

【问题讨论】:

  • 你不能删除(id)演员吗?

标签: objective-c ios pointers automatic-ref-counting cgcolor


【解决方案1】:

您需要连接演员表,以便 ARC 了解您在做什么以及如何应对。检查此问题的已接受答案:ARC and bridged cast

【讨论】:

    【解决方案2】:

    (代表 OP 发布答案)

    我将outerColor 添加到数组中,所以我这样做了:

    CAGradientLayer *maskLayer = [CAGradientLayer layer];
    
    CGColorRef outerColor = [UIColor colorWithWhite:1.0 alpha:1.0].CGColor;
    CGColorRef innerColor = [UIColor colorWithWhite:1.0 alpha:0.0].CGColor;
    
    maskLayer.colors = [NSArray arrayWithObjects:(__bridge id)outerColor, 
                        (__bridge id)innerColor, (__bridge id)innerColor, (__bridge id)outerColor, nil];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 1970-01-01
      • 2017-02-12
      相关资源
      最近更新 更多