<错误>: CGContextSaveGState,CGContextSetStyle,CGContextRestoreGState:无效的上下文0x0。

3
我看到这个问题已经存在一段时间了,但似乎没有人提出一个普适的解决方案,包括我自己。我的三个错误如下:
<Error>: CGContextSaveGState: 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.

<Error>: CGContextSetStyle: 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.

<Error>: 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.

我的应用程序仍然可以正常运行和工作。但是我想知道是否应该担心这个问题。

顺便说一下,我正在使用Xcode 5.0.1,并且该应用程序设置为iOS 7。导致出现错误的视图控制器上的库如下:

In the .h
#import <UIKit/UIKit.h>
#import "Event.h"
#import <MessageUI/MessageUI.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>

In the .m
#import "EventDetailsViewController.h"
#import "XMLReader.h"
#import <Twitter/Twitter.h>
#import "AppDelegate.h"
#import "FBShareViewController.h"
#import <MapKit/MapKit.h>

谢谢


在有上下文可供绘制之前,您需要进行一些调试以找出您要绘制的内容。 - Wain
2
请参考https://dev59.com/z2Ik5IYBdhLWcg3wFKlK。底线是,已知iOS7存在导致此问题的问题。如果您在iOS6下没有看到这个问题,那么可能就是问题所在。否则,它可能是由于在未在“drawRect”中建立上下文或在开始/结束上下文调用之间(例如“UIGraphicsBeginImageContext”和“UIGraphicsEndImageContext”)时不在上下文中的核心图形函数引起的。 - Rob
2个回答

1

如果您正在尝试从UIView获取UIImage,请确保您的UIView已经设置了适当的框架。它不应该在高度或宽度上为0。


0
采纳了@Rob的建议,我去寻找类似的方法,不幸的是,我发现有一个drawRect方法被调用了。我将其注释掉,运行代码,结果没有任何错误。看起来它不会在运行时创建新的上下文,或者是我们需要自己处理的问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接