CGContextSetShadow() - iOS 3.0 和 4.0 之间的阴影方向颠倒了?
我一直在 iPhone 上的 Quartz 绘图代码中使用 CGContextSetShadowWithColor()
来生成文本和其他内容的“踩踏”外观(在 drawRect:
和 中) >drawLayer:inContext:
)。
工作完美,但是当针对 iOS 3.2 和现在的 iOS 4.0 运行完全相同的代码时,我注意到阴影都在相反的方向。例如,在下面的代码中,我将黑色阴影设置为文本上方 1 像素,这使其具有“压入”外观,现在该阴影位于文本下方 1 像素文本,给它一个标准的阴影。
...
CGContextSetShadowWithColor(context, CGSizeMake(0.f, 1.f), 0.5f, shadowColor);
CGContextShowGlyphsAtPoint(context, origin.x, origin.y, glyphs, length);
...
现在我不知道我是否(或曾经)做错了什么,或者此设置的处理是否发生了变化。我没有应用任何可以向我解释这一点的转换,至少没有意识到。我在一个实例中翻转了文本矩阵,但在其他实例中没有翻转,并且这种行为是一致的。另外,我在 SDK 发行说明中找不到任何有关此内容的信息,所以看来可能是我干的。可能是什么问题?
I've been using CGContextSetShadowWithColor()
in my Quartz drawing code on the iPhone to generate the "stomped in" look for text and other things (in drawRect:
and drawLayer:inContext:
).
Worked perfectly, but when running the exact same code against iOS 3.2 and now iOS 4.0 I noticed that the shadows are all in the opposite direction. E.g. in the following code I set a black shadow to be 1 pixel above the text, which gave it a "pressed in" look, and now this shadow is 1px below the text, giving it a standard shadow.
...
CGContextSetShadowWithColor(context, CGSizeMake(0.f, 1.f), 0.5f, shadowColor);
CGContextShowGlyphsAtPoint(context, origin.x, origin.y, glyphs, length);
...
Now I don't know whether I am (or have been) doing something wrong or whether there has been a change to the handling of this setting. I haven't applied any transformation that would explain this to me, at least not knowingly. I've flipped the text matrix in one instance, but not in others and this behavior is consistent. Plus I wasn't able to find anything about this in the SDK Release Notes, so it looks like it's probably me. What might be the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以这似乎要么是一个错误,要么是苹果故意的;无论哪种方式,为了解决这个问题,我现在使用
UIView
类别。我将阴影 Y 方向设置为 iOS 3.2+ 上应有的方向,但只要我支持 iOS < 3.2 我将使用以下类方法根据设备需要将方向乘以 1 或 -1:这是类别:
So it seems to be either a bug or intentional by Apple; either way in order to solve this I'm now using a
UIView
category. I set the shadow Y direction as it should be on iOS 3.2+, but as long as I'm supporting iOS < 3.2 I'll be using the following class method to multiply the direction either by 1 or -1, as needed by the device:Here's the category:
看来他们没有时间修复这个错误。 :)
It's a bug they didn't get around to fixing, it seems. :)
iOS 4.0 在行为上也有同样的变化(我在将 iPhone 应用程序更新为 4.0 时通过搜索 CGContextSetShadow 找到了这里的方法)。因此,显然,如果您链接到 iPhone OS 3.1.3 及之前的版本,CGContextSetShadow 的行为方式是一种,如果您链接到 iPhone OS 3.2 或更高版本,则行为方式不同。
iOS 4.0 has this same change in behavior (I found my way here by searching on
CGContextSetShadow
while updating my iPhone app for 4.0). So, apparentlyCGContextSetShadow
behaves one way if you link against iPhone OS 3.1.3 and before, and a different way if you link against iPhone OS 3.2 or later.