CGPoint数组

时间:2015-10-08 05:46:37

标签: ios objective-c cgpoint

http://code.tutsplus.com/tutorials/ios-sdk-advanced-freehand-drawing-techniques--mobile-15602

在本教程中,我发现了一条让我想知道的行

  

CGPoint pointsBuffer [CAPACITY];

其中CAPACITY是

#define CAPACITY 100

我尝试过NSLog pointsBuffer,但似乎我无法解决这个问题吗?这对代码有什么用呢?谢谢!

3 个答案:

答案 0 :(得分:1)

如果要打印所有值,则需要遍历整个数组:

for (size_t i = 0; i < CAPACITY; i++)
    NSLog(@"Point %zu = (%f, %f)", i, pointsBuffer[i].x pointsBuffer[i].y);

对代码有什么用处?本教程在第2步中解释了它。

答案 1 :(得分:1)

它是CGPoint的数组,你想要的是这样的:

for (int capacityIndex = 0; capacityIndex < CAPACITY; capacityIndex++) {
    NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[capacityIndex]));
}

或打印特定点:

NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[5])); // To print 6th point.

答案 2 :(得分:-1)

这是一个100分的数组。

你可以NSLog

如果你没有在数组索引中指定点,它将返回x = 0,y = 0作为默认点值

NSLog(@"point(%f,%f)",pointsBuffer[0].x,pointsBuffer[0].y);

您可以将值分配给数组索引

pointsBuffer[1].x = 120.0;
pointsBuffer[1].x = 130.0;
NSLog(@"point(%f,%f)",pointsBuffer[1].x,pointsBuffer[1].y);