2013-04-10 24 views
0

我有一個NSTextView,我用來顯示一個計時器。這個計時器每秒鐘更新到00:00。當計時器更新NSTextView的字符串時,NSTextView的行爲就好像它重繪,但使用其父視圖背景作爲自己的背景。NSTextView繼承父母更新的視圖背景

我的NSTextView有一個清晰的背景色,並且已被設置爲不繪製其背景。其父視圖爲其自己的背景繪製了3部分圖像。以下是NSTextView的代碼。

_timerLabel = [[NSTextView alloc] init]; 
[self.timerLabel setSelectable:NO]; 
[self.timerLabel setEditable:NO]; 
self.timerLabel.font = fontLoaded ? [NSFont fontWithName:@"DS-Digital" size:26.0f] : [NSFont fontWithName:@"Lucida Grande" size:26.0f]; 
self.timerLabel.textColor = [NSColor colorWithCalibratedRed:(50.0f/255.0f) green:(50.0f/255.0f) blue:(50.0f/255.0f) alpha:1.0f]; 
self.timerLabel.backgroundColor = [NSColor clearColor]; 
[self.timerLabel setDrawsBackground:NO]; 
[self.timerLabel setAllowsDocumentBackgroundColorChange:NO]; 
[self.timerLabel setAlignment:NSCenterTextAlignment]; 
self.timerLabel.string = @"5:11"; 
[self addSubview:self.timerLabel]; 

任何集成開發環境爲什麼會發生?我嘗試了所有我能想到的或在蘋果文檔中找到的東西,而且沒有任何東西能解決我的問題。任何幫助將不勝感激。

之前在NSTextView https://www.dropbox.com/s/za3twd8hb7r1apr/Screen%20Shot%202013-04-10%20at%205.37.10%20PM.png

更新文本在NSTextView https://www.dropbox.com/s/p0bsk63o8yweyqs/Screen%20Shot%202013-04-10%20at%205.37.28%20PM.png

回答

0

更新文本之後,我想通了,發生了什麼事,我想我的情況下,任何人被套牢了同樣的問題分享。

當更新NSTextView(也可以是NSTextField)的文本時,drawRect函數會被更新的NSTextView的rect調用。

在我的情況下,我的繪製矩形繪製了我的NSView的背景的3部分圖像到drawRect函數中提供的矩形。由於rect是NSTextView的字符串,並且已更新爲字符串,因此將重繪我的背景圖像以適應NSTextView的大小。

目前我唯一能提出的解決方案是總是爲我的NSView的邊界繪製我的3部分圖像。

希望從那以後。