延时调用
-
方法1:performSelector
[self performSelector:(SEL) withObject:(id) afterDelay:(NSTimeInterval)]
- SEL 调用哪个方法
- id 参数
- NSTimeInterval 延时时间
-
方法2:NSTimer
NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval) target:(id) selector:(SEL) userInfo:(id) repeats:(BOOL)]
- NSTimeInterval 延迟时间
- id 调用哪个类
- SEL 调用哪个方法
- id
- BOOL 是否重复
-
方法3:GCD
[self performSelector:(SEL) withObject:(id) afterDelay:(NSTimeInterval)] dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 延时执行里面的方法 });