How do I adjust a Quartz 2D context to account for a Retina display?

♀尐吖头ヾ 提交于 2019-12-01 04:58:56

问题


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;
}

}

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 ?


回答1:


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];
}

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.



来源:https://stackoverflow.com/questions/3896968/how-do-i-adjust-a-quartz-2d-context-to-account-for-a-retina-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!