简体   繁体   English

无法在iphone5上显示640x1136图像

[英]can't display 640x1136 image on iphone5

I've added a Default-568h@2x.png launch image to my app. 我已将Default-568h@2x.png启动图像添加到我的应用中。 The app needs to display a second launch image after the "real" launch image. 该应用需要在“真实”启动图像之后显示第二个启动图像。 Because the UIImage imageNamed: method doesn't automatically load the taller image the way it automatically loads retina images, I've added some code to detect the screen size and display the correct image: 因为UIImage imageNamed:方法不会像自动加载视网膜图像那样自动加载较高的图像,所以我添加了一些代码来检测屏幕尺寸并显示正确的图像:

-(void)pickRightImage
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    UIImageView *imgv = [self loadingImage];

    UIImage *img;

    if(result.height == 480)
    {
        img = [UIImage imageNamed:@"loading_screen.png"];
    } else if([UIScreen mainScreen].scale == 2.f && result.height == 568) {
        // iPhone 5
       img = [UIImage imageNamed:@"loading_screen-568h@2x.png"];       
    }
    [imgv setImage:img];
}

The imageView takes up the whole screen in the NIB, which is named MainWindow, and I have selected the checkbox named "Full Screen At Launch" However, the image never takes up the whole screen. imageView占据了NIB中名为MainWindow的整个屏幕,并且我选中了名为“启动时全屏”的复选框。但是,图像从未占据整个屏幕。 (Although the launch image does.) The second image is letter boxed just as if it were a smaller image, and I had never included the tall launch image. (尽管启动图像可以。)第二个图像用字母框起来,就好像它是一个较小的图像一样,而且我从未包括过高的启动图像。

Is there anyway to programmatically display a full screen image on the 4 inch iphone5? 无论如何,是否可以在4英寸iphone5上以编程方式显示全屏图像? Why is my image always resized? 为什么我的图像总是调整大小?

[UIImage imageNamed:] will take care of adding the @2x for you. [UIImage imageNamed:]将为您添加@2x So you should just specify 所以你应该指定

img = [UIImage imageNamed:@"loading_screen-568h.png"];

It's also useless to test both a 4" screen AND the Retina criteria (scale = 2). All devices that have a 4" screen (568px tall) are Retina displays, so you can assume that if height == 568, the user has an iPhone 5 : replace 同时测试4英寸屏幕和Retina标准(比例= 2)也没有用。所有具有4英寸屏幕(高568px)的设备都是Retina显示器,因此可以假设如果height == 568,则用户具有iPhone 5:更换

if ([UIScreen mainScreen].scale == 2.f && result.height == 568)

with

if ([UIScreen mainScreen].bounds.size.height == 568)

and you're good. 而且你很好。

I tested this on the main view controller. 我在主视图控制器上进行了测试。 Also, on Target > Summary > Status Bar > Visibility check "Hide during application launch". 另外,在“目标”>“摘要”>“状态栏”>“可见性”上,选中“在应用程序启动期间隐藏”。

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImageView *iv = [[UIImageView alloc] initWithFrame:self.view.bounds];
    iv.image = [UIImage imageNamed:@"Second-default568h@2x.png"];
    [self.view addSubview:iv];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM