回滚绘制矩形:
有没有办法在不刷新当前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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您还没有开始在上下文中绘图,则可能只从
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 theclearsContextBeforeDrawing
property of the view to NO before.After starting to draw in the context, the view/layer will always update its content.