第一種:
[UIView animateWithDuration:3 delay:3 options:1 animations:^{
self.btn.transform = CGAffineTransformMakeTranslation(300, 400);
} completion:^(BOOL finished) {
NSLog(@"view animation結束");
}];//不會阻塞線程,animations block中的代碼對于是支持animation的代碼,才會有延時效果,
對于不支持animation的代碼 則 不會有延時效果
第二種:
[NSThread sleepForTimeInterval:3];//阻塞線程,浪費性能 ,一般不推薦用
第三種:最常用
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
});//定制了延時執行的任務,不會阻塞線程,效率較高(推薦使用)
第四種:
[self performSelector:@selector(test) withObject:nil afterDelay:3];//不阻塞線程