产品需求:
点击滑动条上任意位置,就从这个位置开始播放视频/音频并且进度条位置也发生相应变化
实现思路:
扩展一个UISlider子类,在子类方法中重写
-(void)touchesBegan:(NSSet <UITouch *>
方法
*)touches withEvent:(UIEvent *)event
代码具体实现:
//滑块的点击轴换位置
//实际上是一个触摸方法
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
CGRect t = [self trackRectForBounds: [self bounds]];
float v = [self minimumValue] + ([[touches anyObject] locationInView: self].x - t.origin.x - 4.0) * (([self maximumValue]-[self minimumValue]) / (t.size.width - 8.0));
[self setValue: v];
[super touchesBegan: touches withEvent: event];
double current = v * [AudioPlayer shareInstance].player.duration;
[[AudioPlayer shareInstance].player setCurrentTime:current];
}