我正在使用 iOS 5.1 开发应用程序,我遇到了 default.png 文件的一些奇怪行为。
我已将以下文件添加到我的应用程序中:
Default.png - (iPhone)
Default@2x.ping - (iPhone Retina)
Default-Portrait~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"];
我应该这样做吗?你觉得这很有趣吗?
最佳答案
有关官方信息,请查看:App-Related Resources
对于 Launch 图像,请使用此格式:
<basename><orientation_modifier><scale_modifier><device_modifier>.png
看起来你最好使用:
Default.png - (iPad)
Default@2x.png - (iPad Retina)
Default~iphone.png - (iPhone)
Default@2x~iphone.png -(iPhone Retina)
即使简单地使用,这也应该给你正确的图像:
splashView.image = [UIImage imageNamed:@"Default"];
关于iOS 5.1 和 Default.png,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10122750/