繁体   English   中英

iOS通用应用程序,启动图像

[英]iOS universal app which launch image

我正在写一个支持旋转的通用应用程序。 应用启动时,需要从互联网下载一些数据,所以我推了一个带有活动指示器的UIViewController,因为它不可能具有动画启动图像或向其添加标签或对象。

我希望“加载” VC具有与启动相同的bg图像,但是,因为它是通用应用程序,所以我无法设置简单的[UIImage imageNamed:@“ Default.png”],因为它可以在iPhone或Windows XP上运行。 iPad,以及iPad是否可以纵向或横向启动(iPhone应用程序始终以纵向启动)。

问题是:有一种方法可以知道哪个Default.png被用作启动图像? 有可能

  • Default.png(@ 2x,如果是视网膜)
  • Default-Portrait.png(@ 2x,如果是视网膜)
  • Default-Landscape.png(如果是视网膜,则为@ 2x)
  • 默认值568h@2x.png

如果现在有办法,我将检查currentDevice和方向并手动设置imageNamed。

谢谢,马克斯

没有人像和风景的后缀。 您将必须使用[[UIDevice currentDevice] orientation]手动检查[[UIDevice currentDevice] orientation]

表示用于iPad和iPhone / iPod Touch的不同的图像,你可以添加~ipad到iPad的图像的结束和~iphone到iPhone / iPod Touch的图像结束。 例:

Default〜iphone.png将在iPhone / iPod Touch上加载,而Default〜ipad.png将在iPad / iPad上加载:

[UIImage imageNamed:@"Default.png"];

不过,iPhone 5也没有说明符。 因此,您必须检查[[UIScreen mainScreen] bounds].size.height然后再次手动加载UIImage


完整(未经测试)示例:

UIImage *image;

if ([UIScreen mainScreen].bounds.size.height == 568.0)
{
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
    {
        image = [UIImage imageNamed:@"Default-568h-Landscape"];
    }
    else
    {
        image = [UIImage imageNamed:@"Default-568h-Portrait"];
    }
}
else
{
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
    {
        image = [UIImage imageNamed:@"Default-Landscape"];
    }
    else
    {
        image = [UIImage imageNamed:@"Default-Portrait"];
    }
}
// check suggested by Guy Kogus
if (image == nil) image = [UIImage imageNamed:@"Default"];

要在评论中回答您的问题:

不可以,您无法查询运行时使用了什么启动映像。

@ 2x后缀是自动选择的,因此您不必为此担心。 您需要执行一些检查:

- (NSString *)defaultImage
{
    NSString *imageName = nil;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        if ([UIScreen mainScreen].bounds.size.height == 568.0)
        {
            imageName = @"Default-568h";
        }
        else
        {
            imageName = @"Default";
        }
    }
    else // ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
        {
            imageName = @"Default-Landscape";
        }
        else // if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
        {
            imageName = @"Default-Portrait";
        }
    }
    return [UIImage imageNamed:imageName];
}

暂无
暂无

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

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