How to make a static image appear after 3 seconds?

后端 未结 4 1044
后悔当初
后悔当初 2021-01-26 12:50

How would I make an image appear after 3 seconds?

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 13:05

    I'm a big fan of using GCD (iOS 4+) because you can simplify your code with inline blocks.

    In your case, you should set the image to hidden in Interface Builder, then create an IBOutlet with a connection to an ivar in your class.

    Then you can simply run this in viewDidLoad or similar:

    dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 3.0); 
    dispatch_after(delay, dispatch_get_main_queue(), ^(void){
        yourImage.hidden = NO;
    }); 
    

提交回复
热议问题