延迟操作

来源:互联网 发布:淘宝的主营业务 编辑:程序博客网 时间:2024/06/09 20:11


1. GCD 延迟5秒在主线程执行

(延迟5执行block里面的代码)

// 创建线程 time(第一个参数从现在开始第二个参数延迟的时间)

dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)5.0 * NSEC_PER_SEC); 

dispatch_after(time, dispatch_get_main_queue(), ^{


     self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(nextPicture) userInfo:nil repeats:YES];

            [self.timer fire];

    

});


2. 主线程延迟执行 5s

[NSThread sleepForTimeInterval:5];



3. self.tom这个对象 延迟self.tom.animationDuration  执行 setAnimationImages:这个方法

[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration] 


0 0
原创粉丝点击