CGContextSaveGState:无效上下文0x0仅在设备上出错

mat*_*bor 26 xcode core-graphics xcode7

更新:我正在使用Swift 2.0的XCode 7 Beta

当我尝试在iPhone上运行我的应用程序时,我得到以下3个错误:

<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
<Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
<Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Run Code Online (Sandbox Code Playgroud)

当我启用CG_CONTEXT_SHOW_BACKTRACE变量时,我得到这个:

Backtrace:
      <<redacted>+40>
       <<redacted>+432>
        <<redacted>+144>
         <<redacted>+172>
          <<redacted>+332>
           <<redacted>+112>
            <<redacted>+820>
             <<redacted>+688>
              <<redacted>+356>
               <<redacted>+80>
                <<redacted>+808>
                 <<redacted>+344>
                  <<redacted>+420>
                   <<redacted>+104>
                    <<redacted>+284>
                     <<redacted>+556>
                      <<redacted>+504>
                       <<redacted>+1792>
                        <<redacted>+220>
                         <<redacted>+284>
                          <<redacted>+920>
                           <<redacted>+168>
                            <<redacted>+184>
                             <<redacted>+56>
                              <<redacted>+24>
                               <<redacted>+540>
                                <<redacted>+724>
                                 <CFRunLoopRunSpecific+384>
                                  <<redacted>+460>
                                   <UIApplicationMain+204>
                                    <main+164>
Run Code Online (Sandbox Code Playgroud)

我不确定如何解释这个,我没有在我的代码中使用任何CoreGraphics内容,而其他类似问题的答案对我不起作用.我理解在没有代码的情况下帮助调试可能很困难,但我无法弄清楚与此相关的代码,所以如果有人有想法我可以发布更多代码.

Mar*_*nek 52

从我的实验来看,这似乎是由于定义UIViewControllerBasedStatusBarAppearanceInfo.plist.

它发生在iOS 9(beta和GM)上,但不是8.4.

  • 这仍然发生在Xcode 7.0的发布版本中. (19认同)
  • 这还有XCode 7 GM,iOS9 GM.但是,检查一下:将`UIViewControllerBasedStatusBarAppearance`设置为**YES**(即使状态栏被隐藏,这就是为什么我将它设置为NO开始),并且警告消失.疯! (7认同)
  • @Olie:你的回答对我有用.你应该把它作为答案而不是评论. (3认同)

Oli*_*lie 11

在@ JimRota的建议下,将其转化为答案,因为它被认为是有用的:

这还有XCode 7 GM,iOS9 GM.但是,检查出来:设置UIViewControllerBasedStatusBarAppearance为YES(即使状态栏被隐藏,这就是为什么我把它设置为NO开始),警告消失了.疯!

然后我必须将其添加到我的视图控制器以保持状态栏隐藏:

- (BOOL) prefersStatusBarHidden
{
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

对我来说,我所有的VC实际上都是继承自的ProjectNameViewController,所以简化了一下.