【问题标题】:(iphone) i'm getting black rectangle behind image, why?(iphone) 我在图像后面出现黑色矩形,为什么?
【发布时间】:2011-02-18 09:34:04
【问题描述】:

我有 UIImageView 子类实例,它有多个图像子层。

我想为这个视图动态添加/移除阴影。

对于具有一个子层的 imageView,以下代码可以正常工作(imageView 子类的实现),但对于具有多个子层的 imageView,显示黑色矩形而不是阴影。

(实际上,对于一层图像,如果多次运行,代码似乎会在前一个阴影之上不断添加阴影,但这是一个小问题)

- (void) drawLayer: (CALayer*) layer inContext: (CGContextRef)context
{   
    SYSLOG(LOG_DEBUG, "in drawLayer, isShadowed: %d", isShadowed);

    if(isShadowed == true)
    {
        CGContextSaveGState(context);
        CGContextClearRect(context, self.bounds);
        CGContextSetShadow(context, CGSizeMake(10, 10), 3);
        CGContextBeginTransparencyLayer(context, NULL);
        [layer renderInContext:context];
        CGContextEndTransparencyLayer(context);
        CGContextRestoreGState(context);
    }
    else
    {
        [layer renderInContext:context];
    }
}

谢谢

【问题讨论】:

    标签: iphone shadow layer


    【解决方案1】:

    如果您的图层的opaque 不是“否”,CGContextClearRect 将绘制黑色,而不是在图层上打一个透明的孔。我猜这就是问题所在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-26
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多