iPhoneのマイク入力レベルをトリガーして読み取るタイマー設定があります。着信ボリュームが「this」の場合、ビューの背景色を「this」に変更するというifステートメントがいくつかあります。
すべて正常に動作しますが、当然、メーターは0、1、2、3、4、5の連続で移動し、5、4、3、2、1,0の逆の順序で戻ります。しかし、私はこれが起こらないようにしたいと思います。音量を下げようとしたときに、「0」までジャンプして戻したいです。
だから私がしたことは、2つの変数を作成することでした。1つは「previousValue」と呼ばれ、もう1つは「currentValue」と呼ばれ、現在のレベルの連続のどこにあるかを追跡します。次に、previousValue> currentValue(下がる)の場合は「0」に戻るという最後のifステートメントです。ただし、機能していません。多分私はここで何か間違ったことをしていますか?
少しの助けをいただければ幸いです!ありがとうございました!これが私が達成しようとしていることをよりよく見ることができるようにコードです。
INT値を実装intpreviousValueの下で宣言します。int currentValue;
次に、viewDidLoad previousValue=0で開始点を設定します。currentValue = 0;
if (meterResults > 0.0) {
NSLog(@"0");
self.view.backgroundColor = [UIColor redColor];
previousValue = currentValue;
currentValue = 0;
}
if (meterResults > 0.1){
NSLog(@"1");
self.view.backgroundColor = [UIColor yellowColor];
previousValue = currentValue;
currentValue = 1;
}
if (meterResults > 0.2){
NSLog(@"2");
self.view.backgroundColor = [UIColor blueColor];
previousValue = currentValue;
currentValue = 2;
}
if (meterResults > 0.3){
NSLog(@"3");
self.view.backgroundColor = [UIColor greenColor];
previousValue = currentValue;
currentValue = 3;
}
if (meterResults > 0.4){
NSLog(@"4");
self.view.backgroundColor = [UIColor purpleColor];
previousValue = currentValue;
currentValue = 4;
}
if (previousValue > currentValue) {
NSLog(@"Hello, don't go in reverse order go straight to Red");
self.view.backgroundColor = [UIColor redColor];
}