Joe*_*oey 3 iphone xcode splash-screen objective-c xcode4
我有一个简单的iPhone应用程序,加载速度非常快,因此启动画面只显示几分之一秒.有没有办法控制启动画面显示的时间?我四处搜寻,但没有找到任何看似可行的东西.我是否必须使用我的初始图像创建子视图?如何控制显示时间并在子视图和主视图之间切换?
虽然我同意这里表达的观点以及另一个关于为什么你不应该"滥用"默认屏幕的问题,但在我看来实现这种效果是非常微不足道的:
启动时,只需放置一个看起来与启动画面完全相同的视图,然后使用它NSTimer
来关闭它.真的很容易.
// viewDidLoad
[self performSelector:@selector(dismiss)
withObject:nil
afterDelay:yourTimeIntervalInSectons];
// dismiss
[self performSegueWithIdentifier:@"ID" sender:nil];
Run Code Online (Sandbox Code Playgroud)
但是,每次应用程序变为活动状态时都不会出现启动画面.我曾经在我的应用程序环境中做了一个非常具体和有用的目的 - 但Apple拒绝了它.嘿,他们甚至在星期六晚上打电话给我解释给我.
虽然我同意这里所说的所有内容,但我必须使用计时器实现一次启动画面,所以这里是代码:
- (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];
}];
}
Run Code Online (Sandbox Code Playgroud)
只需在AppDelegate -applicationDidFinishLaunching:withOptions:
方法中的某处调用该函数即可
@ asgeo1:代码对我来说效果很好(我在几个项目中使用了类似的代码).为方便起见,我在Dropbox上添加了一个示例项目.
归档时间: |
|
查看次数: |
6813 次 |
最近记录: |