【问题标题】:CGContextRestoreGState: invalid context 0x0 xcode errorCGContextRestoreGState:无效上下文 0x0 xcode 错误
【发布时间】:2013-11-18 22:43:50
【问题描述】:

在我的 iOS 应用程序中,我收到以下错误:

CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

我觉得问题出在这里:

UIImage *buttonImage = [[UIImage imageNamed:@"tanButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 6, 18, 6)];

这发生在运行 iOS7 的 iPhone 5 上。

有谁知道我该如何解决这个问题?

谢谢, 最好的问候

【问题讨论】:

  • 你的按钮有什么作用?
  • 这只发生在 iOS 7 目标上吗?如果您评论这一特定行,错误会消失吗?我问是因为有导致这种警告的 iOS 7 错误。从历史上看,此错误是由于在 drawRect 或手动创建的 CGContextRef 之外调用 Core Graphics 函数导致的,但 iOS 7 中的 UIKit 控件会错误地生成此警告。
  • 是一个按钮,调用一个函数来验证一些变量的状态。如果我将按钮更改为: UIImage *buttonImage = [UIImage imageNamed:@"tanButton.png"];问题已经解决了。但在这种情况下,我失去了想要在按钮中实现的样式。
  • 这是在iOS 7上,我没有在其他目标上测试过,我会检查一下。

标签: ios uiimage cgcontext


【解决方案1】:

我也有这个问题。这是因为当您制作 resizableImageWithCapInsets 时,它需要中心像素来生成平铺图像,如果您的图像高度为 36,您应该这样做: UIEdgeInsetsMake(18, 6, 17, 6),至少给出一个像素平铺在图像的中心。

【讨论】:

    猜你喜欢
    • 2013-09-30
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    相关资源
    最近更新 更多