【发布时间】:2012-04-12 11:35:44
【问题描述】:
我正在使用 iOS 5.1 开发应用程序,但我在使用 default.png 文件时遇到了一些奇怪的行为。
我已将以下文件添加到我的应用程序中:
Default.png - (iPhone)
Default@2x.ping - (iPhone Retina)
默认纵向~ipad.png - (iPad)
Default-Portrait@2x~ipad.png -(iPad Retina)
当应用程序启动时,它似乎为每个场合选择了正确的 Default.png 图像。但是,在我的 AppDelegate 中,我有一个简单的启动画面,可以使应用程序的加载和到应用程序的过渡更加顺畅,执行以下操作:
UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,window.frame.size.width, window.frame.size.height)];
splashView.image = [UIImage imageNamed:@"Default"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
但是[UIImage imageNamed:@"Default"] 反过来并没有为每个设备选择正确的文件,我相信问题出在文件名的-Portrait 部分。
所以作为一个快速的解决方案,我这样做了:
if( ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ) {
// Force the image used by ipads
if( [[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0) {
splashView.image = [UIImage imageNamed:@"Default-Portrait@2x~ipad"];
}
else {
splashView.image = [UIImage imageNamed:@"Default-Portrait~ipad"];
}
}
else
splashView.image = [UIImage imageNamed:@"Default"];
我应该这样做吗?你觉得这很有趣吗?
【问题讨论】:
-
你觉得这很有趣吗?这很有趣
-
试试 NSLogging 看看到底发生了什么。
-
@rokjarc 当您执行简单的
[UIImage imageNamed:@"Default"]时,您如何 NSLog 哪个文件正在被 SDK 选择? -
我在你的 if/else 分支中谈论 NSLoging,你是定义文件名的那个。我现在看到我误解了你的问题。很快就会写一个答案。