UI基础-定时任务

方法1:performSelector

// 1.5s后自动调用self的test方法
[self performSelector:@selector(test) withObject:nil afterDelay:1.5];

方法2:GCD

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    // 1.5s后自动执行这个block里面的代码
    self.myView.alpha = 0.0;
});

方法3:NSTimer

// 1.5s后自动调用self的test方法
[NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(test) userInfo:nil repeats:NO];
// repeats如果为YES,意味着每隔1.5s都会调用一次self的test方法
原文地址:https://www.cnblogs.com/luoze/p/5467544.html