簡體   English   中英

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 中對其進行了解釋。

它是一個CGPoint數組,你想要的是這樣的:

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

或打印特定點:

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

這是一個 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM