0

30 秒間、0.025 秒ごとに電話をかける必要があります。これが私の 0.025 秒のタイマーです。

NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval: 0.025 target: self
                    selector: @selector(GetScreen:) userInfo: nil repeats:YES ];

これを 30 秒に制限するにはどうすればよいですか?

4

2 に答える 2

0

何らかの条件が満たされるまで待機しようとしている場合は、タイマーを使用しないでください。デリゲート パターン、通知/オブザーバー、セマフォなどを使用します。

GetScreen:30 秒後に 1 回(getScreen:通常の Obj-C 慣習による)呼び出したい場合は、次のようにします。

[ NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector( getScreen: ) userInfo:nil repeats:NO ] ;
于 2012-05-17T18:10:31.170 に答える
0

30 秒間だけ継続したい場合は、メンバー変数を作成して 30 秒に達するまでインクリメントし、タイマーをオフにします。

CGFloat timerTotal_;

//initialize it where you create your timer
timerTotal_ = 0.0f;

//every time your GetScreen: is called
timerTotal_+= .025;

if(timerTotal_ > 30)
{
    [myTimer invalidate];
}
于 2012-05-17T18:11:39.667 に答える