0

i have a class NSApplicationDelegate where i will populate the NSMutableArray *coordinate with a lot of coordinate x,y.

how i can tell to the NSViewclass to draw all inside the array? how i can pass the array to NSView class?

thankyou.

4

1 回答 1

1

这取决于坐标在数组中的存储方式,但您可能需要创建一个NSBezierPath

// Maybe make bezPath an instance variable of your view?
NSBezierPath *bezPath = [NSBezierPath bezierPath];

[bezPath setLineWidth:1.0];
// set up other parameters here

[bezPath moveToPoint:NSMakePoint(firstX, firstY)];

// loop over your source coordinates
for (i = 0; i < ... etc ...)
{
    [bezPath lineToPoint:NSMakePoint(source[i].x, source[i].y)];
}

在你的 NSView 的子类的drawRect:方法中,你可以有类似的东西:

- (void) drawRect:(NSRect) dirtyRect
{
    [[NSColor blackColor] set];
    [bezPath stroke];
}

由于您没有提供足够的信息,因此缺少此代码的大部分内容,但是您应该对Cocoa 绘图指南有所了解,它可能会引导您朝着正确的方向前进。

于 2012-04-30T23:58:50.840 回答