- 1,设置slider的thumbImage
//设置进度条的滑动块 [self.progressView setThumbImage:[UIImage imageNamed:@"player"] forState:UIControlStateNormal];
- 2,监听拖动至某处松手播放
//Event:touch up inside
(IBAction)dragToSomePoint:(UISlider *)sender {
self.currentPlayer.currentTime = self.progressView.value*self.currentPlayer.duration;
self.currentPlayTime.text = [NSString stringWithTimerInterval:curr];
}
- 3,监听点击slider的某处,要先添加UITapGestureRecognize
特别注意:获取位置应该用tap的view,宽度用UISlider的宽度
(IBAction)sliderClicked:(UITapGestureRecognizer *)sender {
CGPoint point = [sender locationInView:sender.view];
self.currentPlayer.currentTime = point.x/self.progressView.bounds.size.width*self.currentPlayer.duration;
self.currentPlayTime.text = [NSString stringWithTimerInterval:self.currentPlayer.currentTime];
}
网友评论