產品需求:
點擊滑動條上任意位置,就從這個位置開始播放視頻/音頻并且進度條位置也發生相應變化
實現思路:
擴展一個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];}新聞熱點
疑難解答