Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In my storyboard, I have a view as a splash screen. In this view, I already have a button like "Open Application" that is opening the menu view with a modal segue. But I also want screen to perform segue automatically, like after 2 seconds view appears.

Some code here:

- (void)viewDidAppear:(BOOL)animated
{
    [self performSegueWithIdentifier:@"splashScreenSegue" sender:self];
}

As you can see, I already use performSegueWithIdentifier but it performs immediately. Is there a method to make it delay?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
602 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use GCD's dispatch_after to execute your segue code 2 seconds after the view appears, e.x:

- (void)viewDidAppear:(BOOL)animated 
{
    [super viewDidAppear:animated];

    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self performSegueWithIdentifier:@"splashScreenSegue" sender:self];
    });
}

Additionally, please make sure that you remember to call the super implementation when overriding UIViewController's life cycle methods.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...