iOS 5.1和Default.png [英] iOS 5.1 and Default.png
问题描述
我正在使用iOS 5.1开发一个应用程序,我在default.png文件中遇到了一些奇怪的行为。
I am developing an application using iOS 5.1 and I am experiencing some strange behavior with the default.png files.
我已将以下文件添加到我的应用程序中:
I have added the following files to my application:
Default.png - (iPhone)
Default.png - (iPhone)
Default@2x.ping - (iPhone Retina)
Default@2x.ping - (iPhone Retina)
Default-Portrait~ipad.png - (iPad)
Default-Portrait~ipad.png - (iPad)
Default-Portrait @ 2x ~ipad.png - (iPad Retina)
Default-Portrait@2x~ipad.png -(iPad Retina)
当应用程序启动时,它似乎选择了正确的Default.png图像用于每个场合。但是在我的AppDelegate中,我有一个简单的启动画面,可以使应用程序的加载更顺畅,并转换到应用程序,执行以下操作:
When the application starts it seems that it selects the correct Default.png image to use for each occasion. However in my AppDelegate I have a simple splash screen to make smoother the loading of the application and the transition to the app, doing something like:
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
部分文件名。
However the [UIImage imageNamed:@"Default"]
in turn does not select the correct file for each device, and I believe the problem is the -Portrait
part of the filename.
所以作为一个快速解决方案,我做到了这一点:
So as a quick solution I did this:
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"];
这是我应该这样做的吗?这看起来有趣吗?
Is this how I should be doing this? Does this look funny to you?
推荐答案
有关官方信息,请查看:应用相关资源
For official information here take a look at: App-Related Resources
对于启动图像,请使用以下格式:
For Launch images use this format:
<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)
即使使用简单,这也可以给你正确的图像:
This should give you proper image even if using simply:
splashView.image = [UIImage imageNamed:@"Default"];
这篇关于iOS 5.1和Default.png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!