2

在堆栈溢出的帮助下,我开始熟悉 iPhone 中的石英绘图。我想制作剪辑新月图案的代码,这是我到目前为止所拥有的,但它并没有像我预期的那样工作:

contextRef = UIGraphicsGetCurrentContext();
CGContextSaveGState(contextRef);
onlyDrawTopHalf = YES;
halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
ellipse = CGRectMake(50, 50, 128, 128);
clipRect = CGRectOffset(ellipse, halfMultiplier * ellipse.size.width / 2, 0);
CGContextClipToRect(contextRef, clipRect);
CGContextRestoreGState(contextRef);


onlyDrawTopHalf = YES;
halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
ellipse = CGRectMake(50, 50, 100, 128);
clipRect = CGRectOffset(ellipse, halfMultiplier * ellipse.size.width / 2, 0);
CGContextAddEllipseInRect(contextRef, clipRect);
CGContextEOClip(contextRef);
CGContextFillEllipseInRect(contextRef, ellipse);

准确地说,第一段代码绘制圆(这有效),第二段应该从中剪出椭圆,但这没有按预期工作。

4

1 回答 1

0

两种形状都必须是完美的圆形,而不是椭圆。第二个圆的半径应该小一点,它应该向右(或向左)移动一点,以获得完美的新月效果。

于 2011-12-12T14:09:38.423 回答