NSTimer的用法
来源:互联网 发布:听见下雨的声音 知乎 编辑:程序博客网 时间:2024/04/29 03:52
实现类似油表数字转动效果,用了时间定时器NSTimer,转载一篇小文。
iphone为我们提供了一个很强大的时间定时器 NSTimer,可以完成任何定时功能:
我们使用起来也很简单,只要记住三要素就可以,具体得三要素是:时间间隔NSTimeInterval浮点型,事件代理
delegate和事件处理方法@selector();就可以用
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo; 来初始化一个 时间定时器
下面很简单的例子
-(void)initTimer
{
//时间间隔
NSTimeInterval timeInterval =1.0 ;
//定时器
NSTimer showTimer = [NSTimer scheduledTimerWithTimeIn terval:maxShowTime
target:self
selector:@selector(handleMaxShowTimer:)
userInfo:nil
repeats:NO];
}
//触发事件
- (void)handleMaxShowTimer:(NSTimer *)theTimer
{
NSDateFormatter dateFormator = [[NSDateFormatter alloc] init];
dateFormator.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *date = [dateformater stringFromDate:[NSDate date]];
if([date isEqualToString:@"2010-11-09 23:59:59"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:TITLE_NAME
我们使用起来也很简单,只要记住三要素就可以,具体得三要素是:时间间隔NSTimeInterval浮点型,事件代理
delegate和事件处理方法@selector();就可以用
+ (NSTimer *)scheduledTimerWithTimeIn
下面很简单的例子
-(void)initTimer
{
//时间间隔
NSTimeInterval timeInterval =1.0 ;
//定时器
NSTimer
}
//触发事件
- (void)handleMaxShowTimer:(NSTimer *)theTimer
{