请设置CG_CONTEXT_SHOW_BACKTRACE环境变量 [英] please set CG_CONTEXT_SHOW_BACKTRACE environmental variable
问题描述
尽管查看了3个以上的帖子(2015年制作),但都没有解决我的问题。
Despite looking over more than 3 post (made in 2015) about this problem, non have solved mine.
每次运行时,都会绘制一个简单的代码一行使用UIBezierPath的程序将向我返回:
When ever I run, a simple, code to draw a line using UIBezierPath the program would return me this:
:CGContextSetStrokeColorWithColor:无效上下文0x0。如果您
要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE
环境变量。
: CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextSetFillColorWithColor:无效上下文0x0。如果您
要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE
环境变量。
: CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextSaveGState:无效上下文0x0。如果要查看
的回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextSetLineWidth:无效上下文0x0。如果要
查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextSetLineWidth: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextSetLineJoin:无效上下文0x0。如果要查看
的回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextSetLineJoin: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextSetLineCap:无效上下文0x0。如果要查看
的回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextSetLineCap: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextSetMiterLimit:无效上下文0x0。如果要
查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextSetMiterLimit: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextSetFlatness:无效上下文0x0。如果要查看
的回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextSetFlatness: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextAddPath:无效上下文0x0。如果要查看
的回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextAddPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextDrawPath:无效上下文0x0。如果要查看
的回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextRestoreGState:无效上下文0x0。如果要
看到回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境
变量。
: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
@interface line : UIView
UIBezierPath *myPath;
.........
@implementation
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches]anyObject];
CGPoint touchLocation = [touch locationInView:self];
myPath = [UIBezierPath bezierPath];
[myPath moveToPoint:touchLocation];
}
- (void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches]anyObject];
CGPoint touchLocation = [touch locationInView:self];
[myPath addLineToPoint:touchLocation];
[[UIColor blackColor]setStroke];
[[UIColor greenColor]setFill];
[myPath stroke];
}
如果我要使用drawRect绘制
If I was to draw using drawRect
- (void) drawRect:(CGRect)rect {
....
}
不会弹出错误。我想知道是否由于 touchesBegan
和 touchesMoved
无法执行绘制而收到这些错误?
No error would pop up. I was wondering If I was receiving these errors because touchesBegan
and touchesMoved
can't perform drawing?
在可可(OS X)中,我曾经使用 setNeedsDisplay
,但在可可触摸中并不存在。
In cocoa (OS X) I used to use setNeedsDisplay
, but it doesn't exist in cocoa touch.
我要问的是,是否有消除这些错误的方法,或者还有另一种在运行时绘制 UIBezierPath
的方法。 / p>
All I'm asking is, is there anyway to remove these errors or is there another way to draw UIBezierPath
during run time.
推荐答案
发生无效的上下文错误,因为您尝试使用 drawRect:$之外的绘图操作c $ c>方法,因此没有设置当前图形上下文。
Invalid context errors happen, because you are trying to use drawing operations outside of drawRect:
method, so no current graphic context is set.
就像在OS X上一样,您应该在 drawRect:$中执行绘制c $ c>方法,然后使用
setNeedsDisplay
更新生成的图像。 setNeedsDisplay
和 setNeedsDisplayInRect:
方法都可用于iOS上的UIView。
Like on OS X, you should perform drawing in drawRect:
method, and use setNeedsDisplay
to update resulting image. And both setNeedsDisplay
and setNeedsDisplayInRect:
methods are available for UIView on iOS.
因此,结果应如下所示:
So, result should look like this:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches]anyObject];
CGPoint touchLocation = [touch locationInView:self];
myPath = [UIBezierPath bezierPath];
[myPath moveToPoint:touchLocation];
}
- (void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches]anyObject];
CGPoint touchLocation = [touch locationInView:self];
[myPath addLineToPoint:touchLocation];
[self setNeedsDisplay];
}
- (void) drawRect:(CGRect)rect {
[[UIColor blackColor]setStroke];
[[UIColor greenColor]setFill];
[myPath stroke];
}
这篇关于请设置CG_CONTEXT_SHOW_BACKTRACE环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!