CGPoint 数组
Array of CGPoint
http://code.tutsplus.com/tutorials/ios-sdk-advanced-freehand-drawing-techniques--mobile-15602
在本教程中,我发现了让我感到奇怪的一行
CGPoint pointsBuffer[CAPACITY];
容量在哪里
#define CAPACITY 100
我试过NSLog pointsBuffer,但好像不行,谁能给我解释一下?这对代码有何用处?谢谢!
如果要打印所有值,则需要遍历整个数组:
for (size_t i = 0; i < CAPACITY; i++)
NSLog(@"Point %zu = (%f, %f)", i, pointsBuffer[i].x pointsBuffer[i].y);
对代码有什么用?教程在步骤 2 中对其进行了解释。
这是一个包含 100 个点的数组。
你可以使用 NSLog
如果您不在数组索引中分配点,它将return 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);
它是一个 CGPoint
的数组,你想要的是这样的:
for (int capacityIndex = 0; capacityIndex < CAPACITY; capacityIndex++) {
NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[capacityIndex]));
}
或打印特定点:
NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[5])); // To print 6th point.
http://code.tutsplus.com/tutorials/ios-sdk-advanced-freehand-drawing-techniques--mobile-15602
在本教程中,我发现了让我感到奇怪的一行
CGPoint pointsBuffer[CAPACITY];
容量在哪里
#define CAPACITY 100
我试过NSLog pointsBuffer,但好像不行,谁能给我解释一下?这对代码有何用处?谢谢!
如果要打印所有值,则需要遍历整个数组:
for (size_t i = 0; i < CAPACITY; i++)
NSLog(@"Point %zu = (%f, %f)", i, pointsBuffer[i].x pointsBuffer[i].y);
对代码有什么用?教程在步骤 2 中对其进行了解释。
这是一个包含 100 个点的数组。
你可以使用 NSLog
如果您不在数组索引中分配点,它将return 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);
它是一个 CGPoint
的数组,你想要的是这样的:
for (int capacityIndex = 0; capacityIndex < CAPACITY; capacityIndex++) {
NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[capacityIndex]));
}
或打印特定点:
NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[5])); // To print 6th point.