(3) 计时器NSTimer
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
- (NSDate *)fireDate; 获得计时器开始时间
- (void)invalidate; 关闭计时器
NSTimer
//timerWithTimeInterval创建的timer需要添加到主线程中才能执行
self.timer = [NSTimer timerWithTimeInterval:1.5 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
//scheduledTimerWithTimeInterval方法创建的无需添加到主线程即可执行
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self
selector:@selector(nextImage) userInfo:nil repeats:YES];
//停止定时器
[self.timer invalidate];
self.timer = nil;