在iOS开发中,通常延时执行的方法有
1、
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(SetVideoPlay) object:nil];//该方法是取消还即将要执行的方法
[self performSelector:@selector(SetVideoPlay) withObject:nil afterDelay:1.0];//该方法是延迟1s即将要执行的方法
通常这种延时方法会配套使用上面着两种方法,这种方法不会阻塞线程。
2、定时器 NSTimer//这个是使用最为广泛的方法,这个方法可以延时执行一次,也可以延时无限次循环执行,不会阻塞线程。
[NSTimer scheduledTimerWithTimeIn<wbr>terval:1.0f target:self selector:@selector(delayMethod) userInfo:nil repeats:NO];</wbr>可以通过NSTimer类的- (void)invalidate;取消执行。
3、sleep//这个延时会阻塞线程
[NSThread sleepForTimeInterval:1.0f]; [self delayMethod];4、GCD线程
iOS 延时常用是这三种方法