您的位置:首页 > 移动开发 > IOS开发

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: