第一种方式 NSTimer
-(void)firstTimer{
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(action) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
//停止定时器
// [timer invalidate];
}
-(void)action{
NSLog(@"action.....");
}
第二种方式 CADisplayLink
-(void)secondTimer{
CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLink)];
displayLink.frameInterval = 60;
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
//停止定时器
// [displayLink invalidate];
}
-(void)handleDisplayLink{
NSLog(@"handleDisplayLink.....");
}