在我的基於視圖的NSTableView中,每個視圖(除其他外)都有一個NSTextField和一個位於文本字段下方的NSImageView。NSTextField在NSTableView中模糊,當圖像插入一行時
有時候,當我在表的頂部插入新行,此行中的NSImageView有圖像,在其他行文本變得模糊/降級。
滾動數次後,文字再次變爲正常。
不正常:
OK:
一個例子,其中的文本僅僅是行模糊所述一個與後我法師:
這真的讓我覺得這是從.insertRows
或noteHeightOfRows
未來的問題。
所有元素都在IB中設置了自動佈局約束。
滾動視圖在IB中設置CoreAnimation圖層。在製備細胞時,我也使用層:
cell.layer?.isOpaque = true
cell.textLabel.layer?.isOpaque = true
有時
cell.layer?.borderColor = someColor
cell.layer?.borderWidth = someWidth
行是插入有:
// update the model, then:
NSAnimationContext.runAnimationGroup({ (context) in
context.allowsImplicitAnimation = true
self.table.insertRows(at: index, withAnimation: [.effectGap])
})
更新與所述圖像的行:
// in tableViewCell, while populating the table
cell.postImage.image = img
cell.postImage.needsDisplay = true
// once the image is downloaded
table.reloadData(forRowIndexes: ..., columnIndexes: ...)
table.noteHeightOfRows(withIndexesChanged: ...)
如何避免此問題?這很難調試,因爲它不總是發生,我不明白什麼時候它發生的原因。
你好,也許圖像推文半像素遠離它是不可或缺的位置 - 而這些事情是造成模糊的文本。 – ColdSteel
哦,有趣的想法。也許自動佈局的問題呢?我不知道我應該如何調試這個,雖然... – Moritz
你可以用非常簡單的方式進行測試 - 在表視圖繪製之後(佈局子視圖或任何它調用的對象(對不起,我不是AutoLayout風扇,因爲這樣的事情))只是將文本框的框架重置爲整體框架 - 並強制顯示... 這樣的事情 '[myTetxField setFrame:NSIntegralRect(myTextField.frame)];' – ColdSteel