【问题标题】:How can I invoke a method automatically 20 times per second?如何每秒自动调用一个方法 20 次?
【发布时间】:2010-10-24 11:44:54
【问题描述】:

我习惯于从 JavaScript 创建一个间隔并指定重新调用函数的延迟,直到我停止该间隔。 iPhone上有类似的东西吗?任何好的链接都非常感谢。这将转到社区 wiki。

【问题讨论】:

    标签: iphone cocoa-touch uikit


    【解决方案1】:
    //create and start timer
    
    [NSTimer scheduledTimerWithTimeInterval: 0.05 target: self selector: @selector(timerMethod:) userInfo: nil repeats: YES];
    
    // method works 20 times per second
    -(void) timerMethod: (NSTimer*)theTimer {
    NSLog(@"timer is working");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-22
      • 2019-02-01
      • 2020-03-12
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      相关资源
      最近更新 更多