问题描述
我有一个直接绘制到上下文的Quartz 2D游戏。出于这个原因,我不得不调整代码,以便在适合Retina显示器时进行缩放。我使用以下代码执行此操作:
I have a Quartz 2D game which draws directly onto a context. For this reason I am having to adapt the code so that it scales if appropriate for a Retina display. I am doing this using the following code:
- (CGFloat) displayScale
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
return [[UIScreen mainScreen]scale];
}
else
{
return 1.0;
}
}
我现在正在努力的是如何在我的 -drawRect:
方法中操作我的Quartz上下文,以便通过返回的 scale
价值。任何人都可以帮我这个代码吗?
What I am now struggling with is how to manipulate my Quartz context in my -drawRect:
method to mulitply by the returned scale
value. Can anyone help me with this code ?
推荐答案
你不需要改变Quartz代码中的任何东西来解释Retina显示。如果在您的UIView或CALayer上使用如下代码设置了正确的 contentScaleFactor
:
You don't need to change anything in your Quartz code to account for the Retina display. If the correct contentScaleFactor
is set on your UIView or CALayer using code like the following:
if ([view respondsToSelector:@selector(setContentScaleFactor:)])
{
view.contentScaleFactor = [[UIScreen mainScreen] scale];
}
你在 -drawRect中进行的二维绘图:
或 -drawInContext:
将自动呈现为Retina显示屏。请记住,为Quartz绘图指定的坐标将以点为单位,而不是像素。 Retina显示屏的比例因子为2.0,1点= 2像素。
the 2-D drawing you do within -drawRect:
or -drawInContext:
will be automatically rendered sharply for the Retina display. Remember that the coordinates you specify for the Quartz drawing will be in points, not pixels. With a scale factor of 2.0 for a Retina display, 1 point = 2 pixels.
请参阅部分了解更多信息。
See the "Updating Your Custom Drawing Code" section in the iOS Application Programming Guide for more.
这篇关于如何调整Quartz 2D上下文以考虑Retina显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!