ios的延迟执行的方法
01 @implementation NSObject (PerformBlockAfterDelay) 02 03 - (void)performBlock:(void (^)(void))block 04 afterDelay:(NSTimeInterval)delay 05 { 06 block = [[block copy] autorelease]; 07 [self performSelector:@selector(fireBlockAfterDelay:) 08 withObject:block 09 afterDelay:delay]; 10 } 11 12 - (void)fireBlockAfterDelay:(void (^)(void))block { 13 block(); 14 } 15 16 @end
1 void RunBlockAfterDelay(NSTimeInterval delay, void (^block)(void)) 2 { 3 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*delay), 4 dispatch_get_current_queue(), block); 5 }
1 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*1), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 2 dispatch_async(dispatch_get_main_queue(), ^{ 3 [self alertLabelWithStr:@"计划同步成功"];//执行的方法 4 }); 5 });
dispatch_time的第二个参数是过多少纳秒执行
1 [UIView animateWithDuration:0.0 delay:5.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 2 } completion:^(BOOL finished) { 3 //do stuff here 4 }];
1 [[NSOperationQueue mainQueue] addOperationWithBlock:aBlock];
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。