iOS 延时处理的多种机制
2018-07-06 本文已影响11人
JMong
static int coinCount = 0;
- (void)getCoinAction:(UIButton *)btn{
coinCount = 0;
for (int i = 0; i<30; i++) {
//方法一:延迟调用函数
[self performSelector:@selector(initCoinViewWithInt:) withObject:[NSNumber numberWithInt:i] afterDelay:i * 0.01];
//方法二:延时 注意时间要乘i 这样才会生成一串,要不然就是拥挤在一起的
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(i*0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self initCoinViewWithInt:[NSNumber numberWithInt:i]];
});
}
}
- (void)initCoinViewWithInt:(NSNumber *)i
{
NSLog(@"3333333333333");
}