iPhone开发:最简单的NSTimer暂停和继续

这里有复杂一点的代码 https://bitbucket.org/charliefish/nstimer-extras/overview

更复杂一点的 http://www.koders.com/objectivec/fidD825DEAF6757C8329759D217D17E821176EB2789.aspx?s=%22Denis+Defreyne%22


为NSTimer添加一个类别

#import "TFTimer.h"


#import <Foundation/Foundation.h>


@interface NSTimer (TFAddition)


-(void)pauseTimer;
-(void)resumeTimer;

@end




#import "TFTimer.h"


@implementation NSTimer (TFAddition)


-(void)pauseTimer{

if (![self isValid]) {
return ;
}

[self setFireDate:[NSDate distantFuture]];   //如果给我一个期限,我希望是  4001-01-01 00:00:00 +0000


}


-(void)resumeTimer{

if (![self isValid]) {
return ;
}

//[self setFireDate:[NSDate dateWithTimeIntervalSinceNow:0]];
[self setFireDate:[NSDate date]];

}


@end

你可能感兴趣的:(iPhone开发)