iOS编程 NStimer的使用
2015-07-25 23:46
543 查看
NSTimer在非主线程中,要用NSRunloop而且要在新线程中开起要不会阻塞原线程
- (void)addRunloop
{
_moveTime=[NSTimer
scheduledTimerWithTimeInterval:nChangeTime
target:self
selector:@selector(animalMoveImage)
userInfo:nil
repeats:YES];
[[NSRunLoop
currentRunLoop] addTimer:_moveTime
forMode:NSDefaultRunLoopMode];
[[NSRunLoop
currentRunLoop] run];
_isTimeUp=NO;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self=[super
initWithFrame:frame]) {
NSUInteger x=0;
NSThread *t=[[NSThread
alloc] initWithTarget:self
selector:@selector(addRunloop)
object:nil];
[t
start];
}
return
self;
}
- (void)addRunloop
{
_moveTime=[NSTimer
scheduledTimerWithTimeInterval:nChangeTime
target:self
selector:@selector(animalMoveImage)
userInfo:nil
repeats:YES];
[[NSRunLoop
currentRunLoop] addTimer:_moveTime
forMode:NSDefaultRunLoopMode];
[[NSRunLoop
currentRunLoop] run];
_isTimeUp=NO;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self=[super
initWithFrame:frame]) {
NSUInteger x=0;
NSThread *t=[[NSThread
alloc] initWithTarget:self
selector:@selector(addRunloop)
object:nil];
[t
start];
}
return
self;
}
相关文章推荐
- iOS开发中 Mac OS X 及Xcode 常用快捷键
- iOS动画之大雪纷飞
- iOS 多线程GCD 四
- iOS 多线程NSThread 三
- iOS 多线程pthread 二
- ios8.1.3Cydia重装
- iOS 多线程简介 一
- ios 解决Unknown type name 'CGRect'或者CGFlot不能用
- iOS OC NSNumber转为BOOL
- iOS - 如何集成支付宝
- iOS 记住密码\自动登录
- 关于怎么向Xcode6 IOS8之后向项目中添加预编译文件
- iOS解析XML实现省市区选择
- iOS设计模式 - 适配器
- 小白学开发(iOS)OC_self 与 类方法 和 对象方法(2015-07-25)
- 小白学开发(iOS)OC_面向对象总结(2015-07-25)
- 依赖注入——让iOS代码更简洁
- IOS实现在后台执行一定时间的任务
- iOS开发-Block回调
- VS2015 use C# for iOS