为什么这会报告无效的上下文?
<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.
这发生在调用drawInRect
UIImage 上的类别方法时:
- (UIImage *)myImagePaddedToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
CGSize oldSize = self.size;
CGRect rect = (CGRect){
{
floorf((newSize.width-oldSize.width)/2),
floorf((newSize.height-oldSize.height)/2)
},
oldSize
};
[self drawInRect:rect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
我的理解是,这UIGraphicsBeginImageContextWithOptions
建立了我所吸引的背景。这似乎通常是关心,但我很少会遇到这种失败。
这是 Xcode 5.1.1 附带的 iOS 7 模拟器。