Bre*_*toe 2 iphone objective-c quartz-2d ios
我已经用弧形绘制了我的上下文路径,将其设置为剪辑,并将图像绘制到该剪辑中.
CGContextBeginPath(context);
CGContextMoveToPoint(context, lineStartPoint.x, lineStartPoint.y);
CGContextAddArc(context, lineStartPoint.x, lineStartPoint.y, 105, toAngle*M_PI,fromAngle*M_PI , 1);
CGContextMoveToPoint(context, toLinePoint.x, toLinePoint.y);
CGContextClip(context);
[[UIImage imageNamed:@"gradientfill.png"] drawInRect:[self bounds]];
Run Code Online (Sandbox Code Playgroud)
这完美地工作,如此图所示

我的问题是,在该渐变的底部,我画了一个我想要存在于剪辑之外的圆圈,它应该看起来像这样

如何让我的上下文停止剪辑,以便我可以在剪辑之外拥有该圆圈?
我绘制圆圈的代码是
CGMutablePathRef path = CGPathCreateMutable();
CGRect toHandleRect = CGRectMake(toLinePoint.x-5, toLinePoint.y-5, 10, 10);
CGPathAddEllipseInRect(path, NULL, toHandleRect);
CGContextAddPath(context, path);
CGPathRelease(path);
Run Code Online (Sandbox Code Playgroud)
我希望用户能够将小圆圈拖到该视图中的任何位置.
您可以发出CGContextSaveGState + CGContextRestoreGState对,如以下示例所示:
// Saves the context including the current clipping region.
CGContextSaveGState(context);
// Build you clip region and do some drawing
CGContextBeginPath(context);
CGContextMoveToPoint(context, lineStartPoint.x, lineStartPoint.y);
CGContextAddArc(context, lineStartPoint.x, lineStartPoint.y, 105, toAngle*M_PI,fromAngle*M_PI , 1);
CGContextMoveToPoint(context, toLinePoint.x, toLinePoint.y);
CGContextClip(context);
[[UIImage imageNamed:@"gradientfill.png"] drawInRect:[self bounds]];
CGMutablePathRef path = CGPathCreateMutable();
CGRect toHandleRect = CGRectMake(toLinePoint.x-5, toLinePoint.y-5, 10, 10);
CGPathAddEllipseInRect(path, NULL, toHandleRect);
CGContextAddPath(context, path);
CGPathRelease(path);
// Restore the original state
CGContextRestoreGState(context);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
620 次 |
| 最近记录: |