【问题标题】:Images from Bundle doesn't show using iPad Retina 64-bit and real device使用 64 位 iPad Retina 和真实设备时,Bundle 中的图像不显示
【发布时间】:2014-10-18 01:19:20
【问题描述】:

我使用 UIPageviewcontroller(滚动类型)创建了一个照片滚动应用程序,它使用 viewcontroller 来获取图像。该应用程序在 iPad 和 iPad 视网膜模拟器中运行良好。但它没有在 iPad Retina 64 位和真实设备中显示任何图像。

我的代码是:

UIImageView *background =[[UIImageView alloc] initWithFrame:CGRectMake(0,0,screenHeightPortrait,screenWidthPortrait)];
NSString *imageFile = [[NSBundle mainBundle] pathForResource:self.mainImageLink ofType:nil];
background.image = [UIImage imageWithContentsOfFile:imageFile];
[self.view addSubview:background];

self.mainImageLink 是一个 NSArray 元素。例如是“image1.png”。

我试图在 SO 中找到解决方案并尝试:

  • 确保“image1.png”区分大小写正确且位于复制包资源中。
  • 从复制包资源中删除“image1.png”,清除缓存,然后重新添加。
  • 将“image1.png”放入一个名为“images”的真实文件夹中(它在Xcode中以蓝色文件夹图标显示),确保它在复制包资源中,然后将self.mainImageLink更改为:“images/image1.png”。 png"
  • 试过上面的试验,使用 self.mainImageLink: "image1.png" 和 NSString *imageFile = [[NSBundle mainBundle] pathForResource:self.mainImageLink ofType:nil inDirectory:@"images"];
  • 清除构建缓存(cmd+shift+option+k)
  • 使用 rm -r /Users/User/Library/Developer/XCode/DerivedData/ 删除派生数据
  • 如果我是 NSLog(@"image:%@",imageFile);结果是:image: /Users/my_user/Library/Application Support/iPhone Simulator/7.1-64/Applications/E16A2B0F-F766-41E4-A973-67CA79ED0F9C/myApp.app/images/image1.png,我确保它在复制包资源中并使用 Finder 找到了图像

有什么我错过的吗?非常感谢任何线索或提示..

谢谢!

PS: 我正在使用 XCode 5.1.1 和 SDK iOS 7 + OSX 10.8.5 + MBP 2.5Ghz Core2Duo

【问题讨论】:

  • 您是否尝试将高度和宽度设置为特定的浮点数?如果仅在 64 位设备中发生,则可能是转换 floatCGFloat 的问题。
  • 你是指 UIImageView 的框架吗?我正在使用:CGRect screenBound = [[UIScreen mainScreen] bounds]; CGSize screenSize = screenBound.size; CGFloat screenWidthPortrait = screenSize.width; CGFloat screenHeightPortrait = screenSize.height;
  • 这正是我的意思。尝试使用静态数字。以防万一。
  • 抱歉,没用。我试过: UIImageView *background =[[UIImageView alloc] initWithFrame:CGRectMake(0,0,1024,768)];
  • 我尝试将图像复制到文档目录。但它仍然只在 iPad 和 iPad 视网膜模拟器上显示。在 iPad 视网膜 64 位和我的 iPad 2 设备上不显示。还有其他线索吗?

标签: ios objective-c xcode ipad


【解决方案1】:

其他一些用户对 64 位设备也有同样的问题。尽管正确实施,但某些图像在 64 位设备中无法从捆绑包中显示。

您可以查看此SO Answer。它可能会解决您的问题。

【讨论】:

    猜你喜欢
    • 2016-10-02
    • 2012-01-28
    • 1970-01-01
    • 2012-08-09
    • 2017-01-27
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多