xcode iPhone 闪屏:“Default.png”显示在模拟器上,但不显示在 iPhone 上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2233860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone Splash: "Default.png" displays on simulator but not the iPhone
提问by WoodenKitty
I'm trying to give my iPhone a splash screen.
我正在尝试给我的 iPhone 一个启动画面。
I've placed Default.pngin my resources group. When I run the simulator it is displayed as expected, however when I install my application to the iPhone, no splash screen is displayed.
我已将Default.png放在我的资源组中。当我运行模拟器时,它按预期显示,但是当我将我的应用程序安装到 iPhone 时,没有显示启动画面。
Does anyone know what the cause/solution to this problem is?
有谁知道这个问题的原因/解决方案是什么?
Thanks!
谢谢!
回答by Allisone
If Default.png is not showing up in device, but simulator... then try the following.
如果 Default.png 未显示在设备中,而是显示在模拟器中...然后尝试以下操作。
- Be sure you delete any"default.png", "Default.png", "Default.PNG", etc. that you might have created in several wrong attemps from within XCode and in Finder.
- Delete the App on your iPhone/iPod/iPad
- In Xcode Build->Clean All Targets
- In Finder go to your project and locate the build folder, delete all folders in there.
- Create a new Default.png like in the following example:
- Connect iPhone/iPod to Mac.
- Start your App on iPhone
- In XCode launch Organizer (Window->Organizer)
- Select your connected Device
- You should see a tab "Screenshots"
- Push the Capture Button, to make a Screenshot of your App
- Push "As Default Image..." Button (This will create the Default.png and add it to your project, so that's a really handy thing)
- Build and Run again. It should work now
- 确保删除了在XCode 和 Finder中多次错误尝试创建的任何“default.png”、“Default.png”、“Default.PNG”等。
- 删除 iPhone/iPod/iPad 上的应用程序
- 在 Xcode Build->Clean All Targets
- 在 Finder 中,转到您的项目并找到 build 文件夹,删除其中的所有文件夹。
- 创建一个新的 Default.png,如下例所示:
- 将 iPhone/iPod 连接到 Mac。
- 在 iPhone 上启动您的应用程序
- 在 XCode 中启动 Organizer (Window->Organizer)
- 选择您连接的设备
- 您应该会看到一个选项卡“屏幕截图”
- 按下捕获按钮,为您的应用程序制作屏幕截图
- 按“作为默认图像...”按钮(这将创建 Default.png 并将其添加到您的项目中,因此这非常方便)
- 再次构建并运行。现在应该可以用了
Problems can occur due to wrong format (should be 320 width and 480 height (yes, that means you can see the status bar in your default.png)) or because you might have named the first file default.png (WHICH IS WRONG), which worked in simulator because it seems to be case insensitive but then when it gets copied to iPhone, it won't be found, cause it is case sensitive. So it will still be there in build folder (i think) causing a next correctly named Default.png not to override the old default.png in this iPhone build folder and so it might seem, that you can't fix the problem (cause you see Default.png in project, but in build it's still default.png). At least this is my understanding now (afterwards), since for me it simply didn't want to work even though I tried again and again with different solutions from other people. So from my point of view this different file handling (case/not case sensitive) is a mess that you can solve, by simply cleaning all and everything and trying to generate a new Default.png with the organizer (after everything was cleaned).
问题可能是由于格式错误(应该是 320 宽和 480 高(是的,这意味着您可以在 default.png 中看到状态栏))或因为您可能将第一个文件命名为 default.png(这是错误的) ,它在模拟器中工作,因为它似乎不区分大小写,但是当它被复制到 iPhone 时,它不会被找到,因为它区分大小写。所以它仍然会在构建文件夹中(我认为)导致下一个正确命名的 Default.png 不会覆盖这个 iPhone 构建文件夹中的旧 default.png ,所以看起来你无法解决问题(因为您在项目中看到 Default.png,但在构建中它仍然是 default.png)。至少这是我现在(之后)的理解,因为对我来说它根本不想工作,即使我一次又一次地尝试使用其他人的不同解决方案。
If you want a different/modified splash screen. Open the generated Default.png with photoshop/gimp/whatever and edit it.
如果您想要不同/修改的启动画面。使用 photoshop/gimp/whatever 打开生成的 Default.png 并进行编辑。
回答by Lachlan Roche
Make sure your image is 480x320 pixels, and placed in your application at the top level. The frameworks will display this image until your initial view has loaded and is ready for display.
确保您的图像为 480x320 像素,并放置在您的应用程序的顶层。框架将显示此图像,直到您的初始视图已加载并准备好显示。
If you are seeing a black background then there is something amiss, however if you are just seeing your app's initial view then be happy you have managed to launch your app and have it ready for use in good time.
如果您看到黑色背景,则说明有问题,但是如果您只是看到应用程序的初始视图,那么很高兴您已成功启动应用程序并及时准备好使用。
If you really, really want the user to to see your splash screen then slow down your launch by adding a delay into your app before you present the initial view
如果您真的,真的希望用户看到您的启动画面,那么在您呈现初始视图之前通过在您的应用程序中添加延迟来减慢您的启动速度
The file name must be Default.png (with a capital D). Also, do a clean/rebuild of the entire project to ensure the most recent version of the file is being included in the project. Check the filename on the filesystem, it may display differently in XCode.
文件名必须是 Default.png(大写 D)。此外,对整个项目进行清理/重建,以确保项目中包含最新版本的文件。检查文件系统上的文件名,它在 XCode 中的显示可能不同。
回答by coneybeare
Make sure that is is added into the bundle. To do this, select the image in the XCode left navigation panel, get info on the file, and make sure the checkbox for your target is enabled. Also make sure the file is really a png and not just named that way.
确保已将其添加到捆绑包中。为此,请在 XCode 左侧导航面板中选择图像,获取有关文件的信息,并确保启用了目标的复选框。还要确保该文件确实是一个 png,而不仅仅是这样命名。
回答by coneybeare
Just check the spelling ... I think u r using "default.png" instead of "Default.png". just make "d" capital "D" of Default.png .
只需检查拼写......我认为你使用“default.png”而不是“Default.png”。只需将 Default.png 的“d”大写为“D”。
回答by tt.Kilew
Another possible issue that is Default.png is actually Default.jpg that was renamed to .png. This will work fine on the simulator, but won't work on the device.
另一个可能是 Default.png 的问题实际上是 Default.jpg 已重命名为 .png。这在模拟器上可以正常工作,但不能在设备上工作。
回答by Kenny
If you are using an iphone 4 you also need to add a
[email protected] with the size 640*960 px.
That's what fixed it for me.
如果您使用的是 iphone 4,您还需要添加一个大小为 640*960 像素的 [email protected]。
这就是为我修复它的原因。
This naming convention applies to all images in your app btw.
顺便说一句,此命名约定适用于您的应用程序中的所有图像。
回答by Heckman
I know this is old, but I'm having the exact same issue. The image doesn't show on the device, but is fine on the simulator. I noticed a lot of really weird things with my project, like there were 3-4 "Default.png" images in my plist and that there were a few other "Default.png" images in different libraries and stuff that I didn't notice.
我知道这很旧,但我遇到了完全相同的问题。图像没有显示在设备上,但在模拟器上很好。我注意到我的项目中有很多非常奇怪的东西,比如我的 plist 中有 3-4 个“Default.png”图像,并且在不同的库中还有一些其他的“Default.png”图像和我没有的东西注意。
I tried everything to get them to show up, but after creating a new project and setting the launch images to the EXACT same images I was trying to use, they worked fine. The only thing I can think is that somewhere the project gets corrupted and won't figure out what those launch images do.
我尝试了一切让它们出现,但是在创建一个新项目并将启动图像设置为我尝试使用的完全相同的图像后,它们运行良好。我唯一能想到的是项目在某个地方被破坏并且无法弄清楚这些启动图像的作用。
回答by Mark
Had the same problem caused by saving the initial file as default.png, so it should be Default.png
(normal) and [email protected]
(retina) images.
将初始文件保存为 default.png 也有同样的问题,所以它应该是Default.png
(normal) 和[email protected]
(retina) 图像。
Go to your projects plist and add a row "Launch image" - use a different file name. Save your images with this name (and add @2x.png for retina). Should be fine afterwards.
转到您的项目 plist 并添加一行“启动图像” - 使用不同的文件名。使用此名称保存您的图像(并为视网膜添加 @2x.png)。之后应该就好了。
Also, if you've already install the app on device, delete the app from device (as previous installation may not affect the changes).
此外,如果您已经在设备上安装了该应用程序,请从设备中删除该应用程序(因为之前的安装可能不会影响更改)。
回答by Ryan
I had a similar problem, but my images were being displayed as gray or gray bars. It turned out that there was an alpha channel on the PNG images that the simulator was having no problem with, but the iphone wouldn't display. I opened the images in preview on my Mac and re-saved them without the alpha channel and everything worked. Don't know if this is your problem, but it might be worth a try.
我遇到了类似的问题,但我的图像显示为灰色或灰色条。事实证明,模拟器没有问题的 PNG 图像上有一个 alpha 通道,但 iphone 无法显示。我在 Mac 上的预览中打开了图像,并在没有 alpha 通道的情况下重新保存了它们,一切正常。不知道这是否是您的问题,但可能值得一试。