【发布时间】:2011-12-09 17:13:53
【问题描述】:
我画了椭圆:
CGContextFillEllipseInRect(contextRef, CGRectMake(50, 50, 50, 128));
但我只需要一半椭圆,有没有办法剪掉另一半?
【问题讨论】:
标签: iphone core-graphics draw ellipse clip
我画了椭圆:
CGContextFillEllipseInRect(contextRef, CGRectMake(50, 50, 50, 128));
但我只需要一半椭圆,有没有办法剪掉另一半?
【问题讨论】:
标签: iphone core-graphics draw ellipse clip
在调用绘图方法之前,您可以将上下文剪辑到椭圆的一部分:
CGContextSaveGState(contextRef);
BOOL onlyDrawTopHalf = YES;
CGFloat halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
CGRect ellipse = CGRectMake(50, 50, 50, 128);
CGRect clipRect = CGRectOffset(ellipse, 0, halfMultiplier * ellipse.size.height / 2);
CGContextClipToRect(contextRef, clipRect);
CGContextFillEllipseInRect(contextRef, ellipse);
// restore the context: removes the clipping
CGContextRestoreGState(contextRef);
【讨论】:
CGContextClip。查看有关剪切路径的文档:CGContextClip link