2016-12-29 48 views
1

我想知道爲什麼我的窗口如下所示: 2 lines爲什麼用這段代碼(drawRect)渲染2行?

當我調整窗口的大小,一條線保持伸展而另一個保持靜態大小和傾斜。

As you can see, one of the lines keeps to the edges.

奇怪的部分是,我記錄窗口的高度和寬度,每當drawRect被調用。

在應用程序開始時,drawRect方法被調用4次。 strange

我看着這個和意識到這是不實際的大小,移動窗口的大小了一下,得到真正結果。奇怪的是,它跳得如此之快。

enter image description here

奇怪的部分是「鬼」怎麼行仍然存在,我不知道哪一個是鬼!爲什麼?我改變了顯示線條的顏色...和:

enter image description here

這是靜態顯示的一個是被「產生」用我的每個代碼的drawRect之一。

我使用我的drawRect代碼:

- (void)drawRect:(NSRect)dirtyRect 
{ 
    NSLog(@"%f, %f", dirtyRect.size.height, dirtyRect.size.width); 
    NSBezierPath *line = [NSBezierPath bezierPath]; 
    [line moveToPoint:NSMakePoint(NSMaxX([self bounds]), NSMaxY([self bounds]))]; 
    //Sorry about formatting; SO doesn't make it easy to format. 
    [line lineToPoint:NSMakePoint(NSMinX([self bounds]), NSMinY([self bounds]))]; 
    [line setLineWidth:_lwith]; /// Make it easy to see 
    [_lineColor set]; /// Make future drawing the color of lineColor. 

    [line stroke]; 
} 

我問了一些解釋,或者只是任何幫助!由於

回答

1

自我回答

我做了什麼?:我在故事板中的另一個NSView中有我的NSView的子類;子女NSView靜態保持在一定的大小,而NSView(父母/窗口)正在自由移動。請記住,我的孩子NSView的實例保存在我的ViewController中。 我的NSView顯示的是一行,無論如何,只有當我有自己的實例時它纔會改變顏色。

確保你有你的腳本的所有檢查,礦看起來像現在這樣: enter image description here

注意它是多麼整潔只有一個「圖」的觀點;)