【发布时间】: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 位设备中发生,则可能是转换
float和CGFloat的问题。 -
你是指 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