CGContextSaveGState: 无效的上下文 0x0 (Xcode 7 GM)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32490837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:09:57  来源:igfitidea点击:

CGContextSaveGState: invalid context 0x0 (Xcode 7 GM)

xcodeios9xcode7suppress-warnings

提问by Beto

I have this problem after I compiled my code with Xcode 7 GM.

我用 Xcode 7 GM 编译我的代码后遇到了这个问题。

According to Apple this is a bug, but it still seems to be an issue. Everything works fine, but is it possible to get rid of these errors?

据 Apple 称,这是一个错误,但它似乎仍然是一个问题。一切正常,但是否有可能摆脱这些错误?

: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

: CGContextSaveGState: 无效的上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。

: CGContextTranslateCTM: 无效的上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。

: CGContextRestoreGState: 无效的上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。

enter image description here

在此处输入图片说明

Someone in other forums said something about status bar, but I don't have any success to eliminate the message. This is not a huge issue, but it's a useless "error". I'm using Interface Builder.

其他论坛上有人说了一些关于状态栏的内容,但我没有成功消除该消息。这不是一个大问题,但它是一个无用的“错误”。我正在使用界面生成器。

Updated: I used Objective-Cif you use Swift, maybe this is the question you're looking for

更新:如果你使用 Swift,我使用了 Objective-C也许这就是你正在寻找的问题

回答by ernesto

This also happens for me on 7 GM, but removing UIViewControllerBasedStatusBarAppearancefrom Info.plist fixed it for me, as said here.

这也正好给我7 GM,但删除UIViewControllerBasedStatusBarAppearance从Info.plist中固定对我来说,是说在这里

Update: Warning seems to be gone with iOS 9.2

更新:警告似乎在 iOS 9.2 中消失了

回答by Ayman Ibrahim

I'm drawing using UIBezierPath

我正在使用 UIBezierPath

Removing path.fill()removed the warning.

删除path.fill()删除了警告。

回答by Jiao

I have found another cause for this error today.

我今天找到了这个错误的另一个原因。

When I wrote some drawing code in my View Controller class, these errors appeared. I realized that I have to create a UIView subclass and do the drawing steps in the override drawRect function. When I moved the drawing code there, all the errors disappeared.

当我在 View Controller 类中编写一些绘图代码时,出现了这些错误。我意识到我必须创建一个 UIView 子类并在覆盖 drawRect 函数中执行绘图步骤。当我将绘图代码移到那里时,所有错误都消失了。

回答by Volomike

This is a good case to use the debugger. I set a breakpoint in my mainand then used the F7 key to step through the code until the warning appeared. Turns out, there's yet another way this bogus error appears:

这是使用调试器的好例子。我在 my 中设置了一个断点,main然后使用 F7 键单步执行代码,直到出现警告。事实证明,这个虚假错误还有另一种出现方式:

NSColor *myColor = colorFromRGBA(43,51,59,0.95);
[myColor set];
(self.window).backgroundColor = myColor;

It was generating the warning on [myColor set]. Evidently, I didn't need this and commented it out. At that point, the error went away. Your experience may differ, of course.

它在 上生成警告[myColor set]。显然,我不需要这个并将其注释掉。那时,错误消失了。当然,您的体验可能会有所不同。

回答by deepax11

Restart the device. It fixed my problem.

重启设备。它解决了我的问题。