timer定时器 - iOS 下拉时NSTimer不执行。
PHPz
PHPz 2017-04-17 17:14:20
[iOS讨论组]

在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++)
    }

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

PHPz
PHPz

学习是最好的投资!

全部回复(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];
怪我咯

了解一下RunLoop吧!http://www.jianshu.com/p/4bc01f5269e7

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号