这是我到目前为止所尝试的:
- (void)applicationWillResignActive:(UIApplication *)application
{
timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(triggerTimer:) userInfo:nil repeats:FALSE];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSRunLoopCommonModes];
[runLoop run];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
if (timer && [timer isValid]) {
[timer invalidate];
}
}
我的问题是,如果我使计时器无效,runloop 仍在运行并冻结我的 UI(动画不工作,滚动不工作等)。有什么想法我怎么能做到这一点?
提前致谢!