How to make the splash screen sleep for 4 seconds until the user touches the screen in iphone sdk
I am using splash screen for my application when it starts begining and I made it to sleep for 4 seconds.My need is if user taps on the splash screen before the 4 seconds he should navigate to the next screen.Can any one suggest me with some ideas.
My code I tried was:
- (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 addS开发者_C百科ubview: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];
}
Anyone's help will be much appreciated.
Thank's all, Monish.
Well, you haven't shown us any code or told us what your real problem is, but in pseudo-code I would do something like this:
- (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];
}
}
精彩评论