iPhone清除CGContext [英] iPhone clear CGContext

查看:103
本文介绍了iPhone清除CGContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这段代码创建了一个带有漂亮阴影的圆(我在iPhone上使用MonoTouch.net,当然,Objective-C的答案也很好)

I create a circle with a nice shadow with this code (I use MonoTouch.net for iPhone, Objective-C answers are fine of course)

        UIGraphics.PushContext (ctx);
        SizeF shadowSize = new SizeF (0f, -3f);
        ctx.SetRGBFillColor (194f / 255f, 212f / 255f, 238f / 255f, 1f);
        ctx.SetAllowsAntialiasing (true);
        ctx.SetShadowWithColor (shadowSize, 20, new CGColor (0.9f, 0.7f));
        RectangleF area = new RectangleF (35f, 15f, 210f, 210f);
        ctx.FillEllipseInRect (area);
        UIGraphics.PopContext ();

然后我要添加一条弧线。当我这样做时,颜色和阴影等似乎仍然存在?绘制UIView时如何重新开始? (全部都在同一个UIView中;我正在构建图像)

Then I want to add to it an arc and lines. When I do, the colors and shadow etc seem to stick around? How do I 'start fresh' while drawing my UIView ? (It's all in the same UIView; I am building up the image)

推荐答案

如果您要清除绘制的所有内容,那么您有一块空白的画布,请尝试 CGContextClearRect ,然后再绘制任何内容。

If you mean to clear everything that's drawn so you have a blank canvas, try CGContextClearRect before drawing anything.

但是我想你是说你想要阴影,填充颜色等仅适用于该椭圆,而不适用于随后绘制的对象。为此,您想再次调用相同的状态设置方法,但使用不同的参数。例如, CGContextSetShadowWithColor 需要阴影颜色。但是,如果为该参数传递 NULL ,它将禁用阴影。

But I think you mean that you want the shadow, fill color, etc. to only apply to that ellipse and not to the things that you draw afterward. To do that, you want to call the same state-setting methods again, but with different arguments. For instance, CGContextSetShadowWithColor expects a shadow color. But if you pass NULL for that argument, it will disable shadowing.

另请参见 CGContextSetShadow 文档,其中包含有关禁用阴影的所有方法的说明。选择最适合自己的一款。

See also the CGContextSetShadow documentation, which has a note about all the ways you can disable shadowing. Pick the best one for you.

我认为您的主要问题是您没有利用Apple出色的文档资料。我认为MonoTouch.net本质上是将Objective-C API映射到具有相似或相同符号名称的.NET模块。因此,通过Google的快速搜索,您应该能够在iPhone OS参考库中找到相应的文档。

I think your main problem is that you're not taking advantage of Apple's excellent documentation. I gather that MonoTouch.net essentially maps Objective-C APIs to .NET modules with similar or identical symbol names. So with a quick Google search, you should be able to find the corresponding documentation in the iPhone OS Reference Library.

这篇关于iPhone清除CGContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆