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;
}