【问题标题】:How Do I Use NSTimer, start/stop?如何使用 NSTimer,启动/停止?
【发布时间】:2012-11-06 20:15:03
【问题描述】:

如何使用 NSTimer 让动作每秒发生一次?

问候尼基塔。

【问题讨论】:

  • 请查看您之前的问题并接受其他用户的回答。这将鼓励我们回答您的问题。
  • developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html
  • 谢谢克雷格,从现在开始我会这样做的,

标签: iphone objective-c animation timer nstimer


【解决方案1】:

这样用,

-(void)fireTimer{
   [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selected(timeOut:) userInfo:nil repeats:YES];
}

现在,这将每 1 秒调用一次你的 timeOut: 选择器,然后在 timeOut 中调用:

-(void)timeOut:(NSTimer*)timer{
   static int count = 0;
   count++;
   if(count == 60){
     [timer invalidate]; 
     timer = nil;
   }
}

有很多api。我希望你愿意检查https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

【讨论】:

    猜你喜欢
    • 2012-08-16
    • 1970-01-01
    • 2015-12-08
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    相关资源
    最近更新 更多