1

在这里,我想创建一个自定义 uislider,它类似于媒体播放器向前和向后,即以特定时间间隔以编程方式移动滑块。

例如考虑我有这个视频的视频我需要实现滑块到控制器来向前和向后移动视频内容。

任何示例和教程。

谢谢....

4

2 回答 2

2

这是一个代码,它可以用作类似moviePlayerController的进度条

我希望这段代码对你有帮助

// .M 

@property (nonatomic,strong)UISlider *slider1;

- (void)viewDidLoad
{
    [super viewDidLoad];

    slider1 = [[UISlider alloc] initWithFrame:CGRectMake(10, 400, 300,30)];

    [slider1 setBackgroundColor:[UIColor clearColor]];
    slider1.maximumValue =  1.0;
    slider1.minimumValue = 0.0;
    slider1.continuous = YES;
    [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(updateSlider1) userInfo:nil repeats:YES];
    [slider1 addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:slider1];
    [self.view bringSubviewToFront:slider1];
}

// this method seek video

-(void)sliderAction:(id)sender
{
    float currentValue,TotalValue;
    float value;
    currentValue = self.moviePlayerController.currentPlaybackTime;
    TotalValue = self.moviePlayerController.duration;

    value =self.moviePlayerController.currentPlaybackTime = slider1.value * TotalValue;

}


// Update slider value after each 0.2 sec 
- (void)updateSlider1 {


    float currentValue,TotalValue;
    float value;
    currentValue = self.moviePlayerController.currentPlaybackTime;
    TotalValue = self.moviePlayerController.duration;

   value = (currentValue/TotalValue);

    slider1.value = value;

}
于 2016-02-26T13:37:53.160 回答
1

您可能对此感兴趣;

UISlider 与 ProgressView 相结合

于 2011-01-27T13:29:07.380 回答