到目前为止,这是我的代码:
- (IBAction) startApproximiteLevel:(id)sender {
[getBackgroundLevel startAnimation:self];
float sample1;
float sample2;
float sample3;
float sample4;
float sample5;
float finalSample;
float charlieSoundVolume = [charlieSoundLevel floatValue];
sample1 = charlieSoundVolume;
sleep(1)
sample2 = charlieSoundVolume;
sleep(1)
sample3 = charlieSoundVolume;
sleep(1)
sample4 = charlieSoundVolume;
sleep(1)
sample5 = charlieSoundVolume;
sleep(1);
finalSample = ((sample1 + sample2 + sample3 + sample4 + sample5) / 5);
self.backgroundSoundChange.floatValue = finalSample;
[getBackgroundLevel stopAnimation:self];
}
但这会阻止我的代码的另一部分更新charlieSoundLevel。关于如何在没有睡眠的情况下做到这一点的任何想法()?
利亚
答案 0 :(得分:1)
查看[NSObject performSelector: withObject: afterDelay:]
以在一段时间后在运行循环上启动方法。