I've added a timer with the runloopmode NSEventTrackingRunLoopMode like so:

NSRunLoop *runLoop = [NSRunLoop currentRunLoop];

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.50
                                                  target:self
                                                selector:@selector(targetMethod:)
                                                userInfo:nil
                                                 repeats:YES];


[runLoop addTimer:timer forMode:NSEventTrackingRunLoopMode];

I thought this would only execute whilst for example a menu is open (modal), but it triggers the entire time, even when doing nothing. Is this the normal behavior?

有帮助吗?

解决方案

Yes, this is normal behaviour. You add a timer to the runloopMode which is used for tracking events. This runloop runs all the time and is used to determine if there are events that needs to be processed and passed to your event handlers.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top