0

私は多くの座標x、yNSApplicationDelegateを入力するクラスを持っています。NSMutableArray *coordinate

NSView配列内にすべてを描画するようにクラスに指示するにはどうすればよいですか? 配列を NSView クラスに渡すにはどうすればよいですか?

ありがとうございました。

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 Drawing Guideを見てください。

于 2012-04-30T23:58:50.840 に答える