ios将objc指针转换为struct cgcolorref

时间:2012-05-06 16:16:27

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

我启用了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

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

(代表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];