0

我正在学习斯坦福大学的 CS 193p 课程(在 iTunesU 中),我试图了解他们为 Assigment 3 提供的 AxesDrawer 类,特别是 drawHashMarksInRect 方法的这些行的一部分

#define HASH_MARK_SIZE 3
#define MIN_PIXELS_PER_HASHMARK 25
+ (void)drawHashMarksInRect:(CGRect)bounds originAtPoint:(CGPoint)axisOrigin scale: (CGFloat)pointsPerUnit
{
.....
int unitsPerHashmark = MIN_PIXELS_PER_HASHMARK * 2 / pointsPerUnit;
if (!unitsPerHashmark) unitsPerHashmark = 1;
CGFloat pixelsPerHashmark = pointsPerUnit * unitsPerHashmark;
....
}

他们怎么说使用像素而不使用 contentScaleFactor 属性?他们实际上是在使用像素还是只是点并滥用该术语?这是AxesDrawer 代码

4

2 回答 2

0

The class is correctly treating a point as a point - which means your bounds.size.width and bounds.size.height are the same dimensions as an iPhone 3GS screen's size in pixels...

If you are compiling to an attached 3Gs the content scale factor is 1.

If you are attached to an iPhone 4 or 4s the content scale factor is 2.

However AxesDrawer considers scale as pointsPerUnit, which on an iPhone 4 is 0.5, so the scale you're passing to it is 0.5

You get this by placing the following in the UIView class for the graphing view;

CGFloat screenScale = self.contentScaleFactor;
CGFloat scaleForAxesDrawer = 1 / screenScale;
[[self.axes class] drawAxesInRect:graphArea originAtPoint:axisPoint scale:scaleForAxesDrawer];
// where graphArea is a CGRect and axisPoint is a CGPoint

for example.

AxesDrawer will put a hash mark and number along the axis no less than every 25 pixels.

于 2012-04-20T11:29:20.380 回答
0

但 contentScaleFactor 是每点的像素数。所以在高分辨率的情况下,每点会有更多的像素。但是,既然我们在点范围内交易,系统不应该在不涉及我们的情况下自行处理吗?

于 2015-02-25T07:07:42.217 回答