2012-07-28 278 views
0

我使用UIBezierpath創建了一個圓角矩形,這對我非常有用。只有一個問題,矩形的圓邊具有一種混疊效果。 這裏是一個圖片Aliasing on corners使用RoundedRect對UIBezierpath進行抗鋸齒

我創建了圓角的矩形這樣的:

CGFloat radius = 12; 
CGRect frame1 = CGRectMake(self.bounds.origin.x, self.bounds.origin.y+(self.bounds.size.height/heightFactor), self.bounds.size.width-shadowConst, self.bounds.size.height-(self.bounds.size.height/heightFactor)-shadowConst); 

CGRect frame2 = CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor), self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2)), (self.bounds.size.width/widthFactor)-shadowConst, (self.bounds.size.height/heightFactor)); 

UIBezierPath *result = 
[UIBezierPath bezierPathWithRoundedRect: frame1 cornerRadius:radius]; 
[result appendPath: 
[UIBezierPath bezierPathWithRoundedRect: frame2 cornerRadius:radius]]; 
[result fill]; 
[result addClip]; 
CGContextDrawLinearGradient(context, gradient2, CGPointMake(0, 0), CGPointMake(0, self.bounds.size.height), 0); 

回答

0

至於我可以看到它可能是兩個問題之一:

你顏色繪製結合時顯得很奇怪。灰色的亮綠色可能會讓它看起來很奇怪。

另外,對於你的shadowConst和heightFactor,要小心你沒有分割大小,或者框架的位置是0.5。因此,例如,如果無論您想要的寬度大小是否等於[size].5,它都會畫出模糊的一面。如果將幀的x或y值設置爲[value].5

+0

我也試圖在沒有顏色的情況下繪製它。同樣的鋸齒正在發生... 我不太明白你對常數的含義。 ShadowConst只是一個整數,其值爲3,heightFactor也是一個整數常量。這怎麼會導致別名? 編輯:我的猜測是它是繪圖機制內部的東西。 – arnoapp 2012-07-28 17:21:32

+0

抱歉,直到現在纔看到您的評論。但看到你接受了它,所以我認爲你基於我的提示找出了它:) – runmad 2012-08-08 22:27:15