回滚绘制矩形:

发布于 2024-09-04 01:09:16 字数 487 浏览 2 评论 0原文

有没有办法在不刷新当前UIView的情况下退出drawRect:? 例如:

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetLineWidth(context, 2);

CGContextMoveToPoint(context, 10.0, 30.0);
CGContextAddLineToPoint(context, 310.0, 30.0);
CGContextStrokePath(context);


//I would like to return from here and rollback all changes in drawRect:

}

谢谢!

Is there any way to quit from drawRect: without refresh the current UIView?
For example:

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetLineWidth(context, 2);

CGContextMoveToPoint(context, 10.0, 30.0);
CGContextAddLineToPoint(context, 310.0, 30.0);
CGContextStrokePath(context);


//I would like to return from here and rollback all changes in drawRect:

}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若能看破又如何 2024-09-11 01:09:16

如果您还没有开始在上下文中绘图,则可能只从 drawRect: 返回。之前您必须将视图的 clearsContextBeforeDrawing 属性设置为 NO。

在上下文中开始绘制后,视图/图层将始终更新其内容。

If you haven't started drawing into the context, it might be possible to just return from drawRect:. You'd have to set the clearsContextBeforeDrawing property of the view to NO before.

After starting to draw in the context, the view/layer will always update its content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文