CGContextSetShadow() - iOS 3.0和4.0之间的阴影方向相反?

Pas*_*cal 5 iphone quartz-graphics

我一直CGContextSetShadowWithColor()在iPhone上使用我的Quartz绘图代码来生成文本和其他内容(in drawRect:drawLayer:inContext:)的"stomped"外观.

工作得很好,但是当针对iOS 3.2和现在的iOS 4.0运行完全相同的代码时,我注意到阴影都是相反的方向.例如,在下面的代码中,我将黑色阴影设置为文本上方 1个像素,这使其具有"压入"外观,现在这个阴影比文本 1px ,给它一个标准阴影.

...
CGContextSetShadowWithColor(context, CGSizeMake(0.f, 1.f), 0.5f, shadowColor);
CGContextShowGlyphsAtPoint(context, origin.x, origin.y, glyphs, length);
...
Run Code Online (Sandbox Code Playgroud)

现在我不知道我是否(或曾经)做错了什么或者是否对这个设置的处理有所改变.我没有应用任何可以解释这一点的转换,至少不是故意的.我在一个实例中翻转了文本矩阵,但在其他实例中却没有,这种行为是一致的.另外我在SDK发行说明中找不到任何相关内容,所以它看起来可能就像我一样.可能是什么问题?

Pas*_*cal 3

所以这似乎要么是一个错误,要么是苹果故意的;不管怎样,为了解决这个问题,我现在正在使用一个UIView类别。我设置了 iOS 3.2+ 上应有的阴影 Y 方向,但只要我支持 iOS < 3.2,我将使用以下类方法将方向乘以 1 或 -1,根据需要设备:

...
CGContextSetShadowWithColor(context, CGSizeMake(0.f, [UIView shadowVerticalMultiplier] * -1.f), 0.5f, textShadowColor);
...
Run Code Online (Sandbox Code Playgroud)

这是类别:

@interface UIView (shadowBug) 

+ (NSInteger) shadowVerticalMultiplier;    

@end


@implementation UIView (shadowBug)

+ (NSInteger) shadowVerticalMultiplier
{
    static NSInteger shadowVerticalMultiplier = 0;
    if (0 == shadowVerticalMultiplier) {
        CGFloat systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
        shadowVerticalMultiplier = (systemVersion < 3.2f) ? -1 : 1;
    }

    return shadowVerticalMultiplier;
}


@end
Run Code Online (Sandbox Code Playgroud)