iphone/ipad 自定义 UISlider 控制器

发布于 2024-10-14 10:40:02 字数 142 浏览 10 评论 0原文

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

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

任何示例和教程。

谢谢....

Here i want to create a custom uislider which is similar to media player forward and backward ie programatically moving slider at a particular time interval.

for example consider am having a video for this video i need to implement slider to controller to move forward and backward of video content.

any samples and tutorials.

thanks....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红尘作伴 2024-10-21 10:40:02

这里有一段代码,可以像 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;

}

Here is a code which will work as a progress bar like moviePlayerController

I Hope This code will help you

// .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;

}
浸婚纱 2024-10-21 10:40:02

您可能对此感兴趣;

UISlider 与 ProgressView 组合

This might be of interest to you;

UISlider with ProgressView combined

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文