-
(void) timer{
dispatch_queue_t quque = dispatch_queue_create("myQ", 0);
dispatch_source_t timer=dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quque);uint64_t interval = 1 * NSEC_PER_SEC; // 时间间隔1秒
dispatch_source_set_timer(timer, dispatch_time(0.8, 0), interval, 0); // 延迟0.8秒执行
dispatch_source_set_event_handler(timer, ^{
switch (self.Searchflag) { case 0:{ YYLog(@"启动") break; } case 1:{ dispatch_sync(dispatch_get_main_queue(), ^{ [_searchRedRubineView stopSearchAnimation:^{ _searchRedRubineView.failSearch = YES; }]; dispatch_source_cancel(timer); }); break; } case 2:{ YYLog(@"搜索完毕") // 关闭 dispatch_suspend(timer); YYLog(@"%@",timer) break; } default: break; }
});
dispatch_source_set_cancel_handler(timer, ^{
self.Searchflag = 0;
NSLog(@"cancel");
});dispatch_resume(timer);
网友评论