How to delay Default.png?

2019-02-06 09:37发布

How can I delay the app loading to show the splash screen for longer?

6条回答
SAY GOODBYE
2楼-- · 2019-02-06 10:14

I had a situation where the client had to demo the launch image. So, this was my solution..

- (void)applicationDidBecomeActive:(UIApplication *)application

{

UIImageView *defaultImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default@2x.png"]];
[self.window addSubview:defaultImageView];
sleep(2);
[defaultImageView removeFromSuperview];
[defaultImageView release];
/*
 Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
 */

}

查看更多
女痞
3楼-- · 2019-02-06 10:23

You can use it sleep method to get this result "

sleepForTimeInterval

", If you want to get it launch time, do like :

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
   [NSThread sleepForTimeInterval:8.0];
}

It will delay the launch by 8 seconds

Warning : But it is not recommended by apple, as it will the watchdod about long time for your app loading, It can kill your app. But incase if you need it to get some specific screenshot or for some in-house use, you can use to solve for purpose but never in app submission.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-02-06 10:23

This question is similar: splash screen like tap tap revenge 3

Basically, in your applicationDidFinishLaunching:, add an image view on top of other views containing your Default.png.

查看更多
Deceive 欺骗
5楼-- · 2019-02-06 10:28

You should let the app start as usual then make the first view that appears have the identical image on it as the splash screen. Start a timer and then replace that view with your real application root view after a few seconds.

Deliberately delaying the actual application launch is a big no-no.

查看更多
等我变得足够好
6楼-- · 2019-02-06 10:29

UPDATE: No seriously, DON'T do this!

Or us the C function

sleep(9);

Putting this in applicationDidFinishLaunching: will cause you program to pause for 9 seconds, any other integer may be entered as well.

EDIT: I've learned a lot in the past year. Don't do this. The reason being that the springboard will automatically stop the app launching if it takes too long. That timing is poorly documented so even one second can result in the app failing.

查看更多
The star\"
7楼-- · 2019-02-06 10:29

See the above discussion of why you probably should not delay your app load in this way. But if you happen to have a scenario where sleeping for short duration would be preferable to the overhead of switching out a view, use NSThread's sleepForTimeIntervale instead of sleep(). It's more framework friendly and you have more granular control over the sleep time:

[NSThread sleepForTimeInterval:0.75]
查看更多
登录 后发表回答