控制启动画面的时间

时间:2014-03-17 06:13:14

标签: objective-c xcode ios7

我的项目中有一个启动画面。我在启动图像中添加了图像,它工作正常。但是我需要添加延迟时间只有2秒,而且我触摸启动画面它会转到主页。

1 个答案:

答案 0 :(得分:-1)

您需要创建自己的启动画面,以增强启动画面的持续时间,即创建带有启动画面的控制器并使用计时器关闭它或者您可以这样做

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    //Don't use this as its risky as per one of the comment
    [NSThread sleepForTimeInterval:4.0]; 
    // This will stop further execution and your splash screen would last for 4 extra seconds.

    splashScreen = [[UIViewController alloc] initWithNibName:@"SplashView" bundle:nil]; 
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:splashScreen];
    [window.rootViewController presentModalViewController:navController animated:NO]; 
}

现在在SplashViewController中

-(IBAction)btnLoadScreenTapped:(id)sender{ //This is button touchup inside method we will load main interface from here
    MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    [self.navigationController pushViewController:viewController];
}

注意

根据评论[NSThread sleepForTimeInterval:4.0];之一,使用此方法存在风险,请不要使用。像你已经做的那样去寻找上面的代码。