Sunday, 15 September 2013

UISlider change value smoothly

UISlider change value smoothly

I have a UIslider setting the position for a AVAdioRecording:
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];
}
There are three questions i would like to ask.
1) Why does the animation for the value change not work? 2) Why does the
slider position move only when I release my finger from the button and
does not follow it? 3) Is using an NSTimer the best way to do it? I have
heard that NSTimer is a lot memory consuming...

No comments:

Post a Comment