iOS 下拉时NSTimer不执行。

在UITableview上写了个定时器,每0.1秒旋转一下图片角度

 NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "test", userInfo: nil, repeats: true);

    func test(){
        
        if(angle>360) {
            angle=0;
        }
        print(angle);
        self.pengyouquan_circle.transform = CGAffineTransformMakeRotation(angle++)
    }

刚开始定时器也是都能执行的,但是下拉的时候定时器就自动停止了,这什么情况?
我想让下拉的时候图片也一直在旋转该怎么处理?

图片描述

阅读 5.5k
3 个回答

scheduledTimerWithTimeInterval:
这个方法会默认把你的Timer以NSDefaultRunLoopMode添加到主Runloop上,而当你滑tableView的时候,就不是NSDefaultRunLoopMode了,这样,你的timer就会停了。

改动方法:

    NSTimer *timer = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(test) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
新手上路,请多包涵
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerStart:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSRunLoopCommonModes];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题