如何让启动画面睡眠4秒,直到用户触摸iphone sdk中的屏幕

时间:2010-10-04 10:40:18

标签: objective-c

当我的应用程序开始启动时,我正在使用启动画面,我让它睡了4秒钟。我需要的是如果用户在4秒钟之前点击启动画面,他应该导航到下一个屏幕。可以任何一个建议我提出一些想法。

我试过的代码是:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{    

// Override point for customization after application launch



[self createEditableCopyOfDatabaseIfNeeded];
[self initializeDataStructures];

mainController = [[FavoritesViewController alloc] init] ;
 navController = [[UINavigationController alloc] initWithRootViewController:mainController];
navController.navigationBar.barStyle = UIBarStyleBlack;
[window addSubview:navController.view];
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:@"default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
sleep(4);
// Do your time consuming setup
[splashView removeFromSuperview];
[splashView release];
 [window makeKeyAndVisible];
}

任何人的帮助将不胜感激。

谢谢所有, Monish。

1 个答案:

答案 0 :(得分:1)

好吧,你没有向我们展示任何代码或告诉我们你的真正问题是什么,但在伪代码中我会做这样的事情:

- (void) start {
  [self showSplashScreen];
  fourSecondsRunning = YES;
  // In four seconds, call stop.
  [self performSelector:@selector(stop) withObject:nil afterDelay:4.0];
}

- (void) stop {
  // View wasn't tapped during the last 4 seconds. Do something.
  fourSecondsRunning = NO;
  [self hideSplashScreen];
  [self doSomething];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  if (fourSecondsRunning) {
    fourSecondsRunning = NO;
    // Touched within the four seconds. Make sure "stop" is not called.
    [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
    [self hideSplashScreen];
    [self goToNextScreen];
  }
}