1

How can one introduce a small delay between the time when view loads till the time something shows up.

A half a second would be fine. Is there a more graceful way to handle this other then sleep (1)

A bit more details on what i'd like to do:

 UIImageView *cardView = [[UIImageView alloc] initWithFrame
             :CGRectMake([thisCard xPosition], [thisCard yPosition], 79 , 123)];
        [cardView setImage:[ thisCard faceImage]];
        cardView.transform = CGAffineTransformMakeRotation(.34906585);

       // SLEEP HERE FOR .5 SECONDS

        [thisCard setOwnImageView:cardView];

        [self addSubview:cardView];
James Leonard
  • 3,593
  • 5
  • 27
  • 32
  • You can user `NSTimer` as well. [See this stack overflow page.][1] [1]: http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer – kk1 Mar 13 '15 at 18:01

2 Answers2

6

Set the initial state of all your subviews to hidden and in viewDidLoad add the following code:

    double delayInSeconds = 0.5;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // unhide views, animate if desired
    });

You could also use performSelector:afterDelay:

XJones
  • 21,959
  • 10
  • 67
  • 82
4

Simple. Check out this:

[self performSelector:@selector(fadeOutDialog) withObject:nil afterDelay:2.0];

After a delay of 2 seconds, it then executes the 'fadeOutDialog' method.

Brayden
  • 1,795
  • 14
  • 20
  • Then use just what was stated by XJones: `dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ // unhide views, animate if desired });` but where the comment is place everything else you'd like to unhide or animate in. Try that out. – Brayden Nov 23 '11 at 06:21