xcode 在 iPhone 上更长时间地显示启动/加载屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10094595/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:56:14  来源:igfitidea点击:

Display splash/loading screen longer on iPhone

iphoneobjective-cxcodexcode4splash-screen

提问by Joey

I have a simple iPhone application that loads very quickly, so the splash screen only displays for a fraction of a second. Is there any way to control how long the splash screen displays? I have searched around, and have not found anything that seems like it would work. Do I have to create a subview with my splash image? How would I control its display time and switch between the subview and the mainview?

我有一个简单的 iPhone 应用程序,加载速度非常快,所以闪屏只显示几分之一秒。有没有办法控制启动画面的显示时间?我四处搜索,并没有找到任何看起来可行的东西。我是否必须使用我的初始图像创建子视图?我将如何控制其显示时间并在子视图和主视图之间切换?

回答by Mundi

While I agree with the views expressed here and in the other question about why you should not "abuse" the default screen, it seems to me quite trivial to achieve this effect:

虽然我同意这里表达的观点以及关于为什么不应该“滥用”默认屏幕的另一个问题,但在我看来,实现这种效果非常简单:

When starting up, simply put up a view that looks exactly like the splash screen and use an NSTimerto dismiss it. Really quite easy.

启动时,只需放置一个看起来与启动画面完全相同的视图,然后使用 anNSTimer关闭它。真的很容易。

// viewDidLoad
[self performSelector:@selector(dismiss) 
           withObject:nil 
           afterDelay:yourTimeIntervalInSectons];
// dismiss
[self performSegueWithIdentifier:@"ID" sender:nil];

However, don't have the splash screen come on each time the application becomes active. I once did this for a very specific and useful purpose in the context of my app - but Apple rejected it. Hey, they even called me on Saturday evening to explain it to me.

但是,不要在每次应用程序激活时都出现启动画面。我曾经在我的应用程序上下文中出于非常具体和有用的目的这样做 - 但 Apple 拒绝了它。嘿,他们甚至在星期六晚上打电话给我向我解释。

回答by Wolfgang Schreurs

While I agree with all that's been told here, I had to implement a splash screen with a timer once as well, so here's the code:

虽然我同意这里所说的所有内容,但我还必须实现一个带有计时器的启动画面,所以这里是代码:

- (void)showSplashWithDuration:(CGFloat)duration
{
    // add splash screen subview ...

    UIImage *image          = [UIImage imageNamed:@"Default.png"];
    UIImageView *splash     = [[UIImageView alloc] initWithImage:image];
    splash.frame            = self.window.bounds;
    splash.autoresizingMask = UIViewAutoresizingNone;
    [self.window addSubview:splash];


    // block thread, so splash will be displayed for duration ...

    CGFloat fade_duration = (duration >= 0.5f) ? 0.5f : 0.0f;
    [NSThread sleepForTimeInterval:duration - fade_duration];


    // animate fade out and remove splash from superview ...

    [UIView animateWithDuration:fade_duration animations:^ {
        splash.alpha = 0.0f;
    } completion:^ (BOOL finished) {
        [splash removeFromSuperview];
    }];
}

Just call the function somewhere in your AppDelegate's -applicationDidFinishLaunching:withOptions:method

只需在您的 AppDelegate-applicationDidFinishLaunching:withOptions:方法中的某处调用该函数



@asgeo1:code works just fine for me (I've used similar code in several projects). I've added an example projecton my Dropbox for your convenience.

@asgeo1:代码对我来说很好用(我在几个项目中使用过类似的代码)。为方便起见,我在我的 Dropbox 上添加了一个示例项目

回答by Mick MacCallum

Now, I completely agree with the above posts that you shouldn't do this, but if you still wish to it can be achieved very easily by adding the following to your AppDelegate.m.

现在,我完全同意上述帖子,您不应该这样做,但是如果您仍然希望,可以通过将以下内容添加到您的AppDelegate.m.

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    sleep(2);
}

The "2" represents how many seconds to sleep for. It will accept values like ".5"

“2”代表睡眠的秒数。它将接受像“.5”这样的值

回答by Jonas Schnelli

Don't do this and/or read why here

不要这样做和/或在此处阅读原因

iOS Duration of Splash Screen (Default.png)

iOS 启动画面的持续时间 (Default.png)

It does really make no sense to extend the duration of the Default.png.

延长 Default.png 的持续时间确实没有意义。