首页 > 学院 > 开发设计 > 正文

使用UISlider自定义视频播放器滑动条---视频快进快退功能

2019-11-09 16:40:22
字体:
来源:转载
供稿:网友

产品需求:

点击滑动条上任意位置,就从这个位置开始播放视频/音频并且进度条位置也发生相应变化


实现思路:

扩展一个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];}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表