iOS:在用户交互/滚动时执行操作

Ril*_*eyE 12 uiscrollview ios performselector

我试图让我的应用程序在延迟后执行一个动作,但是必须在用户与a进行交互/滚动时完成UIScrollView.

我不确定为什么既不会performSelector:withObject:afterDelayscheduledTimerWithTimeInterval:target:selector:userInfo:repeats:不会解雇.是因为他们是在后台线程吗?

有什么建议或帮助吗?

Nik*_*uhe 24

双方NSTimerperformSelector:withObject:afterDelay:在默认情况下只有在正常运行的循环模式火灾.滚动时,运行循环处于事件跟踪模式.

您必须在所有常见模式下安排定时操作:

NSTimer *timer = [NSTimer timerWithTimeInterval:0.016 target:self selector:@selector(fire:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
Run Code Online (Sandbox Code Playgroud)

要么

[self performSelector:@selector(fire:) withObject:nil afterDelay:1.0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
Run Code Online (Sandbox Code Playgroud)

还有专门的NSEventTrackingRunLoopMode.