您的位置:首页 > 移动开发 > IOS开发

iOS 关于如何使用延时控件

2016-05-09 16:50 429 查看
在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 延时常用是这三种方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息