「Objective-C」ios開発でNSTimerの使い方を紹介するサンプルコード

1.Timerの基本設定
-(void)initializeTimer {
//Timerの周波数を設定、30回/秒
float theInterval = 1.0/30.0;
fpsLabel.text = [NSString stringWithFormat:@"%0.3f", theInterval];

//Timerが正式に起動
[NSTimer scheduledTimerWithTimeInterval:theInterval
target:self
selector:@selector(countTotalFrames:)
userInfo:nil
repeats:YES];
}

2.使い方
-(void)countTotalFrames:(NSTimer *)theTimer {
frameCount ++;
framesLabel.text = [NSString stringWithFormat:@"%d", frameCount];
}

IOS

Posted by arkgame