- (void)addTimer
{
self.timer = [NSTimerscheduledTimerWithTimeInterval:2.0target:selfselector:@selector(nextImage) userInfo:nilrepeats:YES];
[[NSRunLoopcurrentRunLoop] addTimer:self.timerforMode:NSRunLoopCommonModes];
}
//销毁过程
- (void)removeTimer
{
[self.timer invalidate];
self.timer = nil;
}
当然,上面这段代码,有可能会在主线程中执行,这样会导致线程阻塞。实际使用的话,还是应该开辟新线程
原文地址:http://www.cnblogs.com/ZippoatiOS/p/3755068.html