我试图让我的应用程序在延迟后执行一个动作,但是在用户与UIScrollView进行交互/滚动时必须完成.
@H_404_2@我不知道为什么performSelector:withObject:afterDelay或scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:将触发.是因为他们在后台线程?
@H_404_2@任何建议或帮助?
解决方法
NSTimer和performSelector:withObject:afterDelay:默认情况下只在正常运行循环模式下触发.滚动时,运行循环处于事件跟踪模式.
@H_404_2@您必须按照所有常见模式安排您的定时操作:
NSTimer *timer = [NSTimer timerWithTimeInterval:0.016 target:self selector:@selector(fire:) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];@H_404_2@要么
[self performSelector:@selector(fire:) withObject:nil afterDelay:1.0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];@H_404_2@还有专门的NSEventTrackingRunLoopMode.