- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(update) userInfo:nil repeats:YES];
//NSDefaultRunLoopMode只能处理输入源或定时源其中的一种
//NSRunLoopCommonModes同时处理输入源和定时源
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
CFRunLoopRun();
});
}
- (void)update {
static int i = 0;
NSLog(@"%d", i);
i++;
if (i > 4) {
CFRunLoopStop(CFRunLoopGetCurrent());
i = 0;
}
}