美文网首页
音乐播放之UISlider

音乐播放之UISlider

作者: alige | 来源:发表于2017-02-19 16:25 被阅读172次
    • 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
    图片.png

    特别注意:获取位置应该用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];
    }
    

    相关文章

      网友评论

          本文标题:音乐播放之UISlider

          本文链接:https://www.haomeiwen.com/subject/xdejwttx.html