创buildUIImageView时无效的上下文

我尝试创buildUIImageView时出现错误。 看看这个代码:

UIImage* backgroundPanel = [[UIImage imageNamed:@"loginPanelBackground.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(90, 0, 149, 416)]; self.connexionBackgroundImgView = [[UIImageView alloc] initWithImage:backgroundPanel]; self.connexionBackgroundImgView.frame = CGRectMake(0, 0, 416, 390); // THIS LINE PROVOC THE INVALID CONTEXT [self.connexionView insertSubview:self.connexionBackgroundImgView aboveSubview:self.connexionToCreationCompteView]; 

它会在日志中引发这个错误:

 <Error>: CGContextSaveGState: invalid context 0x0 <Error>: CGContextSetBlendMode: invalid context 0x0 <Error>: CGContextSetAlpha: invalid context 0x0 <Error>: CGContextTranslateCTM: invalid context 0x0 <Error>: CGContextScaleCTM: invalid context 0x0 <Error>: CGContextGetCTM: invalid context 0x0 <Error>: CGContextSaveGState: invalid context 0x0 <Error>: CGContextClipToRect: invalid context 0x0 <Error>: CGContextDrawTiledImage: invalid context 0x0 <Error>: CGContextRestoreGState: invalid context 0x0 <Error>: CGContextGetCTM: invalid context 0x0 <Error>: CGContextSaveGState: invalid context 0x0 <Error>: CGContextClipToRect: invalid context 0x0 <Error>: CGContextDrawTiledImage: invalid context 0x0 <Error>: CGContextRestoreGState: invalid context 0x0 <Error>: CGContextGetCTM: invalid context 0x0 <Error>: CGContextSaveGState: invalid context 0x0 <Error>: CGContextClipToRect: invalid context 0x0 <Error>: CGContextDrawTiledImage: invalid context 0x0 <Error>: CGContextRestoreGState: invalid context 0x0 <Error>: CGContextRestoreGState: invalid context 0x0 

我只有在iPad的这个错误,而不是与模拟器,我不明白..:/

我有这个问题,直到我发现我的cap插入参数resizableImageWithCapInsets:是错误的 – 它没有留下任何un-capped区域(你至less需要1×1像素没有盖帽)。 所以请确保:

(insets.left + insets.right)<width

(insets.top + insets.bottom)<height

模拟器不区分大小写。 该设备区分大小写。 png命名是否正确? 也许这是大写的“login”

在这里看到答案: 如何捕获UITableView / UIScrollView的完整内容的UIImage,并使其在iOS设备上工作

谢谢eliajf!

由于代表低,我仍然不能评论。 不过,我想补充neon1的答案,这帮助了我很多。

你还需要确保所有的插入都大于零。

insets.left> 0

insets.top> 0

insets.right> 0

insets.bottom> 0