7

AVAdioRecording の位置を設定する UIslider があります。

CGRect frame = CGRectMake(50.0, 230.0, 200.0, 10.0);
                     aSlider = [[UISlider alloc] initWithFrame:frame];
                     // Set a timer which keep getting the current music time and update the UISlider in 1 sec interval
                     sliderTimer = [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(updateSlider) userInfo:nil repeats:YES];
                     // Set the maximum value of the UISlider
                     aSlider.maximumValue = player.duration;
                     // Set the valueChanged target
                     [aSlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
                     [self.ViewA addSubview:aSlider];




 - (void)updateSlider {
// Update the slider about the music time

[UIView beginAnimations:@"returnSliderToInitialValue" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:1.3];

aSlider.value = player.currentTime;

[UIView commitAnimations];
}

- (IBAction)sliderChanged:(UISlider *)sender {
// Fast skip the music when user scroll the UISlider
[player stop];
[player setCurrentTime:aSlider.value];
[player prepareToPlay];
[player play];
}

質問したいことが3つあります。

1) 値の変化のアニメーションが機能しないのはなぜですか? 2) ボタンから指を離したときにのみスライダーの位置が移動し、追従しないのはなぜですか? 3) NSTimer を使用するのが最善の方法ですか? NSTimer は多くのメモリを消費すると聞いたことがあります...

4

3 に答える 3

5

おそらくこれらを使用する必要があります。

  1. スライダーを作成するときに、スライダーのプロパティcontinuousをに設定します。YES

    あなたの場合 aSlider.continuous = YES;

  2. 使用setValue:animated方法、

    あなたの場合 [aSlider setValue:player.currentTime animated:YES];

于 2013-09-15T13:33:04.293 に答える