http://code.tutsplus.com/tutorials/ios-sdk-advanced-freehand-drawing-techniques--mobile-15602陣列CGPoint
的在本教程我發現的線使我想知道
CGPoint pointsBuffer [定員];
,其中容量爲
#define CAPACITY 100
我試過的NSLog pointsBuffer,但似乎我不能,任何人都可以給我講解一下?以及這對代碼有用嗎?謝謝!
http://code.tutsplus.com/tutorials/ios-sdk-advanced-freehand-drawing-techniques--mobile-15602陣列CGPoint
的在本教程我發現的線使我想知道
CGPoint pointsBuffer [定員];
,其中容量爲
#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
如果不在數組索引分配點,它將返回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.
做我做錯什麼? – Jamil
本地聲明的數組未被初始化爲0.其值爲垃圾。 –
它可能會垃圾,但它會一直爲0,你可以用這個值來比較任何東西 – Jamil