【发布时间】:2013-09-15 13:26:47
【问题描述】:
我有一个 UIslider 设置 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];
}
我想问三个问题。
1) 为什么数值变化的动画不起作用? 2) 为什么只有当我的手指从按钮上松开而不跟随它时,滑块位置才会移动? 3) 使用 NSTimer 是最好的方法吗?我听说 NSTimer 非常消耗内存...
【问题讨论】:
标签: ios objective-c cocoa-touch uislider