3

我有一个通用二进制应用程序,目前在 iTunes 中发布,并且在 iOS 4.x 到 5.1 上的 iPhone 3、4、4S、iPad 2 上正常工作,但在运行 iOS 5.1 的新 iPad (3) 上显示黑色 UIImage。

有人遇到过这种情况么?有什么修复建议吗?

问题是从 NSData 加载的 UIImage 显示为黑色。

我最初认为 NSData 可能是 nil 或不可读,所以我添加了 UIAlert 和 NSLog 来输出 NSData 长度和 UIImage 大小属性(假设成功将数据读入 UIImage 会产生合理的大小值)。UIAlert 中的一切看起来都不错...

// MyView.m

- (NSData*)getImageData

{      

     Screening *screen = [[Model sharedInstance] screenInProgress];

     return screen.anteriorImage;  // returns the NSData from the managed 'Screening' object

}


- (void)viewWillAppear:(BOOL)animated

{
     NSData *imagedata = [self getImageData];

     UIImage *image = [UIImage imageWithData:imagedata];

     [clientImageView setImage:image];     /// UIImageView in nib




     /// apply user grid
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];


     if ([defaults integerForKey:@"com.ikonetics.posture.gridoverlay"] >= 0) {     

          UIImageView *grid = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"grid.png"]];

          [grid setBackgroundColor:[UIColor clearColor]];

          [grid setAlpha:0.6f];

          [grid setFrame:clientImageView.frame];

          [screenshotWrapper addSubview:grid];     // screenshotWrapper is a UIView in xib arranged as a parent to other views

          [grid release];

     }


     NSString *note = [NSString 

                           stringWithFormat:@"NSData length: %d \nUIImage size: %@ \nUIImage scale: %1.f \nClientImage info: %@"

                           , [imagedata length]

                           , NSStringFromCGSize(image.size)

                           , image.scale

                           , [clientImageView description]

                           ];



     NSLog(@"debug note: %@ ", note);

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"DEBUG INFO" 

                                                                 message:note

                                                               delegate:nil

                                                    cancelButtonTitle:@"OK"

                                                    otherButtonTitles:nil];

     [alert show];   

     [alert release];



}



// Screening.h

@interface Screening : NSManagedObject


@property (nonatomic, retain) NSData * anteriorImage;     // this data is stored elsewhere using UIImageJPEGRepresentation(image, 0.8);
...
@end

显示 UIAlertView 的 iPad 3 的屏幕截图,您可以看到 NSData 有长度,UIImage 有大小,并且 UIImageView (ClientImage) 有合理的框架,并且网格覆盖 UIImage 正确显示,如预期的那样。

  • 返回的 NSData 有长度并且不是nil (下面的 187433)
  • UIImage 能够解析数据并构建图像,通过大小和比例属性证明(784, 980)

iPad 3 截图

最后,这也已在/// apply user grid禁用选项的情况下进行了测试,因此覆盖 png 甚至没有实例化,因为该代码块没有运行。黑色 UIImage 问题仍然存在。

其他人对显示黑色 UIImage 而不是实际图像的 UIImageView 有问题吗?关于如何修复代码以使其在 iPad 3 上正常工作的任何想法或想法?

谢谢!

编辑 - 更多调试信息:

我将 NSData (imagedata) 写到了电子邮件中,这样我就可以在设备上查看它。我想知道图像本身是否为空白/黑色,并了解到数据在保存设备时正确显示为图像(它不是空白的)。

因此,加载到 UIImage 和 UIImageView 中的 NSData 显示为黑色......但是当附加到电子邮件时,它会正确显示图像。

此外,我想确保视图的层次结构按预期显示;检查我的图像是否不在另一个视图下方。从 ViewController 开始view,我记录recursiveDescription并了解到 iPad 3 上的视图层次结构与 iPad 2 匹配,这正是我所期望的。

新的调试代码:

NSString *note = [NSString 
                  stringWithFormat:@"NSData length: %d \nUIImage size: %@ \nUIImage scale: %1.f \nRecursive info: %@"
                  , [imagedata length]
                  , NSStringFromCGSize(image.size)
                  , image.scale
                  , [[self view] recursiveDescription]
                  ];

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"Debug email"];
[mailViewController setMessageBody:note isHTML:NO];
[mailViewController addAttachmentData:imagedata mimeType:@"image/jpg" fileName:@"imagedata.jpg"];

[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];

最后,这是来自 2 和 3 设备的递归日志信息:

iPad 2 日志:

NSData length: 123254 
UIImage size: {800, 960} 
UIImage scale: 1 
Recursive info: <UIView: 0x10a91620; frame = (0 0; 768 960); autoresize = W+H; layer = <CALayer: 0x10a91650>>
   | <UIScrollView: 0x10a90a10; frame = (0 0; 768 960); clipsToBounds = YES; autoresize = RM+TM; layer = <CALayer: 0x10a90bb0>; contentOffset: {0, 0}>
   |    | <UIView: 0x10a90be0; frame = (0 0; 1536 1920); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x10a90c10>>
   |    |    | <UIView: 0x10a90c40; frame = (384 480; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x10a90c70>>
   |    |    |    | <UIImageView: 0x10a908f0; frame = (0 0; 768 960); opaque = NO; autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a90930>>
   |    |    |    | <LineView_iPad: 0x10a90ce0; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a90d20>>
   |    |    |    | <PointView_iPad: 0x10a90dd0; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x10a90e20>>
   |    |    |    | <UIImageView: 0x10a96480; frame = (0 0; 768 960); alpha = 0.6; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x10a966e0>>
   | <UIView: 0x10a91680; frame = (-10 750; 220 220); autoresize = RM+TM; layer = <CALayer: 0x10a916b0>>
   |    | <UIImageView: 0x10a916e0; frame = (0 0; 220 220); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x10a91720>>
   |    | <UIImageView: 0x10a91480; frame = (10 10; 200 200); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a914c0>>
   |    | <UIImageView: 0x10a91840; frame = (102 102; 16 16); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a91880>>

iPad 3 日志:

NSData length: 166252
UIImage size: {784, 980}
UIImage scale: 1
Recursive info: <UIView: 0xc669470; frame = (0 0; 768 980); autoresize = W+H; layer = <CALayer: 0xc667550>>
 | <UIScrollView: 0x33d410; frame = (0 20; 768 960); clipsToBounds = YES; autoresize = RM+TM; layer = <CALayer: 0x325840>; contentOffset: {0, 0}>
 |    | <UIView: 0x308630; frame = (0 0; 1536 1920); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xc666f40>>
 |    |    | <UIView: 0x318970; frame = (384 480; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xc682a70>>
 |    |    |    | <UIImageView: 0xc66cd60; frame = (0 0; 768 960); opaque = NO; autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc672c00>>
 |    |    |    | <LineView_iPad: 0x301680; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x329fa0>>
 |    |    |    | <PointView_iPad: 0xc6841b0; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xc672b10>>
 |    |    |    | <UIImageView: 0xc588b70; frame = (0 0; 768 960); alpha = 0.6; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xc589500>>
 | <UIView: 0x324330; frame = (-10 770; 220 220); autoresize = RM+TM; layer = <CALayer: 0xc687970>>
 |    | <UIImageView: 0xc665b80; frame = (0 0; 220 220); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x321490>>
 |    | <UIImageView: 0x314e50; frame = (10 10; 200 200); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc684f30>>
 |    | <UIImageView: 0x63d220; frame = (102 102; 16 16); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc580d90>>

尽管这篇文章长得令人难以忍受,但我确实希望有人能想到任何可能导致这个问题的事情......

4

1 回答 1

2

这似乎是 iOS 的一个错误。这是解决方法:

  • 在 Interface Builder 中,将 UIImageView 背景纹理更改为任何颜色

而已。

我在调试过程中偶然发现了这一点,同时任意翻转开关试图让一些有趣的事情发生。我的代码/应用程序没有使用 UIImageView 的背景颜色,它的属性没有被调整过......曾经吗?

在我上面的代码中,UIImageView“clientImageView”的背景设置为纹理“View Flipside Background Color”。将该纹理设置为背景,加载的 UIImage 拒绝显示。将背景纹理更改为除 Flipside 之外的任何内容,并且 UIImage 按预期显示。

  • 我们所做的唯一更改是在 Interface Builder 中对 UIImageView 的背景颜色属性进行了更改。
  • 唯一出现错误的地方是运行 iOS 5.1 的 iPad 3 硬件。
  • 它每次都失败并且可以重现
  • 还在 iOS 4.x 到 5.1 上的 Phone 4、4S、iPad 2 上进行了测试

向 Apple 报告为 Bug ID# 11080928

于 2012-03-20T14:06:24.407 回答