xcode 从 xcassets 文件获取启动图像的大小错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20477316/
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
Getting launch image from xcassets file has wrong size
提问by Snowman
Xcode's default Images.xcassets
file has a slot for LaunchImage
, where for a portrait iPhone app there are 5 possible slots.
Xcode 的默认Images.xcassets
文件有一个插槽用于LaunchImage
,其中对于纵向 iPhone 应用程序有 5 个可能的插槽。
According to the documentation, to get an image properly sized from the xcassets
file, just use [UIImage imageNamed:]
.
根据文档,要从xcassets
文件中获取正确大小的图像,只需使用[UIImage imageNamed:]
.
However, running the following code on iPhone Retine (4-inch) simulator:
但是,在 iPhone Retine(4 英寸)模拟器上运行以下代码:
UIImage *splashImage = [UIImage imageNamed:@"LaunchImage"];
NSLog(@"%@", NSStringFromCGSize(splashImage.size));
produces the following output:
产生以下输出:
{320, 480}
which is obviously the wrong size.
这显然是错误的尺寸。
I have made sure that the mappings in the xcassets file are correct, and have confirmed all dimensions. It also seems that I cannot request a specific image from a given set in the xcassets file, meaning I cannot do:[UIImage imageNamed:@"LaunchImageR4"]
.
我已确保 xcassets 文件中的映射正确,并已确认所有维度。它也似乎我不能从xcassets文件一组给定请求特定的图像,这意味着我不能做:[UIImage imageNamed:@"LaunchImageR4"]
。
And since the files are added to an xcassets file, I also do not have access to the raw image files, so a custom solution seems out of the question.
而且由于这些文件被添加到 xcassets 文件中,我也无权访问原始图像文件,因此自定义解决方案似乎是不可能的。
Does anyone have any idea how I would solve this issue?
有谁知道我将如何解决这个问题?
回答by timgcarlson
I believe that the correct launch image is loaded automatically at startup. It is not meant to be pulled from xcassets
during runtime. Since it is at runtime, you will have to do your own check for which device is being used, as the image catalog is only setup to pull retina vs. non-retina using the @2x postfix (not the size of the device).
我相信正确的启动图像会在启动时自动加载。它并不意味着xcassets
在运行时被拉出。由于它是在运行时,您必须自己检查正在使用的设备,因为图像目录仅设置为使用 @2x 后缀(而不是设备的大小)拉视网膜与非视网膜。
You can use this postto determine which device is being used and load the correct image by name.
您可以使用这篇文章来确定正在使用的设备并按名称加载正确的图像。
回答by Guy Kogus
Launch images are a special kind of image set. You can't use [UIImage imageNamed:@"LaunchImage"]
to get the correct launch image that suits your device (i.e. iPhone 3", 4" or iPad + Retina).
启动图像是一种特殊的图像集。您无法使用[UIImage imageNamed:@"LaunchImage"]
来获取适合您的设备(即 iPhone 3"、4" 或 iPad + Retina)的正确启动图像。