【iOS学习】----NSTimer(附Demo)

来源:互联网 发布:淘宝个人尺码设置在哪 编辑:程序博客网 时间:2024/05/16 10:03

Creating a Timer(创建一个timer)

  • 1.  + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds

                                       invocation:(NSInvocation *)invocation

                                          repeats:(BOOL)repeats;

  • seconds计时器触发的秒数,若小于或等于0,则取0.1毫秒。
  • repeats:yes,执行到定时器被宣布无效。NO,执行一次之后就无效了。
  • invocationThe invocation to use when the timer fires. The timer instructs the invocation object to retain its arguments.

  • 2.+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds

                                         target:(id)target

                                       selector:(SEL)aSelector

                                       userInfo:(id)userInfo

                                        repeats:(BOOL)repeat;s

    target:定时器启动时,通过aSelector发送制定消息的对象。对象由定时器retain,在定时器无效时release。

    selector:定时器触发,发送给target的消息。定时器通过本身作为此方法的参数。

    userInfo:传递的参数,可为nil。


  • 3.+ timerWithTimeInterval:invocation:repeats:
  • 4.+ timerWithTimeInterval:target:selector:userInfo:repeats:
  • 5.– initWithFireDate:interval:target:selector:userInfo:repeats:

Firing a Timer(启动timer)

    -fire
Stopping a Timer(停止timer)
    -invalidate
Information About a Timer(timer方法)

  • – isValid
  • – fireDate
  • – setFireDate:
  • – timeInterval
  • – userInfo

下面是我参考网上写的一个例子:
定时器NSTimer

原创粉丝点击