iOS - NSTimer细节记录

2017-05-24  本文已影响0人  小_黑_屋

人一切的痛苦,本质上都是对自己的无能的愤怒。

NSTimer是APP常用控件之一,依然有很多我们平时忽略的地方,如计时器销毁,计时器什么时候是会自动暂停计时的等,这里做一下基本的记录


目录

1. NSTimer的基本属性
2. NSTimer的创建
3. runLoop几种常见模式
4. NSTimer的销毁

NSTimer 的基本属性

NSTimer属性

NSTimer的创建

NSTimer创建方式比较多,这里将其分成两种,一种是创建就自动加入了runLoop的,一种是没有需要手动加入的
 + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation repeats:(BOOL)yesOrNo;

 + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;

 + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void (^)(NSTimer *timer))block API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
  + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation repeats:(BOOL)yesOrNo;

  + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;

  + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void (^)(NSTimer *timer))block API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));

  - (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void (^)(NSTimer *timer))block API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));

  - (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)ti target:(id)t selector:(SEL)s userInfo:(nullable id)ui repeats:(BOOL)rep NS_DESIGNATED_INITIALIZER;

runLoop几种常见模式

NSTimer的销毁

  - (void)dealloc{
    
      [time invalidate];
      time = nil;
    
  }

这里对文章开头的进行各基本小结

文中有些写的不够详细,如果有疑问直接留言,我会及时添加和修改,谢谢。

上一篇 下一篇

猜你喜欢

热点阅读