views:

372

answers:

2

I have a program running beautifully on my iPhone 4. It uses a class UIView I created (called TestView) to draw graphics using Quartz (very simply graphics such as just a few CG lines and circles). I need, however, to take advantage of the new higher resolution screen on the iPhone 4. Currently, the ensure backwards compatibility with iPhone 3, moving by a single "point" in your code causes a movement of 2 pixels on the iPhone 4 screen. By updating a UIView to a scale factor of 2.0, you can change the mapping from logical coordinate space to pixel space to take advantage of the higher resolution of the iPhone 4. It should be easy; I just can't find any documentation on how to change the UIView scale factor.

For example, any line I draw, which should is specified by the function CGContextSetLineWidth(context, 1.0); ends up drawing a line 2 pixels wide. I need to change this to actually draw one pixel wide.

I find explanations but no examples or method for changing scale factors in Apples explanation of supporting hi res screens:

http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/SupportingResolutionIndependence/SupportingResolutionIndependence.html#//apple_ref/doc/uid/TP40007072-CH10-SW12

UIView documentation gives a contentScaleFactor attribute, but no "set" method. Change the line below from ttp:// to http:// to turn into URL:

ttp://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView

+1  A: 

Ok, so the iPhone 4 is good enough to make all of it's UIViews automatically of scale factor 2. The more underlying problem is that CG renders lines in an unusual way (as far as I can tell). If you make the line width to be 1.0/contentScaleFactor (ie 0.5 for iPhone 4), and draw a line straight up and down (or straight side to side), half of the time it will be a perfect, bright line of width one pixel. But the other half of the time, it renders this as a line of width two pixels, with both lines of pixels being only half lit. This looks good in complicated contexts, especially that involve movement, but if you're just examining a single line, it is quite annoying.

A hack to get around this for a single line is to "jiggle" the coordinate by half a value. So if you're drawing from (0,0) to (0,10) and get the "double width" line, try drawing from (0.5, 0) to (0.5, 10).

XcrossY
A: 

Sorry, wrong post.