创建UIImageView时无效上下文



我尝试创建一个UIImageView时会有错误。查看此代码:

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上有这个错误,而不是模拟器,我不明白..:/

我遇到了这个问题,直到我发现我对ResizizableImageWithCapinsets的帽子插图:错误 - 它根本没有留下任何未限制的区域(您至少需要1x1 Pixel,被帽子覆盖)。因此,请确保:

(insets.left intsets.right)&lt;宽度

(intsets.top insets.bottom)&lt;高度

模拟器对情况不敏感。该设备对病例敏感。PNG命名正确吗?也许是用资本L。

"登录"

请参阅此处的答案:如何捕获UITATIONVIEW/UISCROLLVIEW的完整内容的UIImage,并在iOS设备上工作

谢谢Eliajf!

我仍然无法评论较低的代表。但是,我想补充Neon1的答案,这对我有很大帮助。

您还需要确保所有插图都大于零。

insets.left> 0

insets.top> 0

insets.right> 0

insets.bottom> 0

最新更新