我有一個自定義UIView
,它使用其-[drawRect:]
方法繪製。自定義視圖中的奇怪反鋸齒
問題在於抗鋸齒行爲非常奇怪,因爲黑線水平線或垂直線非常模糊。
如果我禁用了與CGContextSetAllowsAntialiasing
的抗鋸齒,則所有內容都按預期繪製。
抗鋸齒:
alt text http://dustlab.com/stuff/antialias.png
無抗鋸齒(這看起來像AA預期的結果):
alt text http://dustlab.com/stuff/no_antialias.png
線寬正好是1,和所有的座標是整數值。
如果我使用CGContextStrokeRect
繪製一個矩形,但是如果我繪製完全相同的CGRect
和UIRectStroke
,則會發生同樣的情況。
除此之外,Apple在Cocoa繪圖指南的「執行像素精確繪圖」部分中提供了一些不錯的提示和示例代碼:http://developer.apple.com/mac/library/documentation/Cocoa/ Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#// apple_ref/doc/uid/TP40003290-CH204-BCICIJAJ – 2009-09-21 16:32:45
這裏是避免沒有任何代碼的簡單方法http://www.techpaa.com/2012/06/avoiding -view-edge-antialiasing.html – ShivaPrasad 2012-06-18 08:31:01
@jeeva'UIViewEdgeAntialiasing'僅適用於圖層的邊緣。問題是關於在Quartz中繪製的線條。 'UIViewEdgeAuthoriasing'不會影響Quartz繪圖。 – 2012-06-20 07:15:24