ios - 尝试绘制 touchesBegan 时出现 CGContext 错误
问题描述
- (void)drawRect:(CGRect)rect {
}
- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
CGContextRef context = UIGraphicsGetCurrentContext();
UITouch* touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextMoveToPoint(context, point.x, point.y);
CGContextAddLineToPoint(context, point.x + 100, point.y);
CGContextStrokePath(context);
}
它给了我错误
[未知进程名称] CGContextSetStrokeColorWithColor:无效上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。[未知进程名称] CGContextMoveToPoint:无效上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。[未知进程名称] CGContextAddLineToPoint:无效上下文 0x0。如果您想查看回溯,请查看 CG_CONTEXT_SHOW_BACKTRACE 环境变量。[未知进程名称] CGContextDrawPath:无效上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。
解决方案
推荐阅读
- apache-spark - 在 spark 中使用动态列名
- python - 在 Heroku 上从 github 构建被卡住,没有任何行被写入
- python - conda 中的新环境可以从基础环境继承特定的包吗
- javascript - 如何从 eslint 中排除文档文件夹
- c# - 从 ASP.NET 中的一个表映射两个实体
- sharepoint - 在 SharePoint 列表中获取 SMS 响应
- java - 如何在android中对api响应进行分组
- php - 如何修复 PHP 嵌套循环我在尝试创建嵌套循环时遇到了一些问题?
- google-bigquery - Google Big query ML ARIMA 预测不正确
- google-api - Google Slides API-如何更改某种颜色的所有形状的文本颜色