如何使用滑块值和与滑块拇指相同的位置运行气泡(在滑块顶部)?

发布于 2024-11-08 01:59:51 字数 698 浏览 3 评论 0原文

我有一个最小值 = 0 且最大值 = 1000 的滑块。滑块上有一个气泡,它与滑块的拇指一起运行并显示滑块的值。 但我无法用滑块拇指运行气泡。 这是代码片段:

CGFloat sliderMax = localSlider.maximumValue;
CGFloat sliderMin = localSlider.minimumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = _dsp;
CGFloat halfMax = (sliderMax+sliderMin)/2.0;
//int hMax = [halfMax intValue];
CGFloat xCoord = halfMax- 55.0;
CGFloat yCoord = (CGFloat)_positionX;
if (sliderValue > halfMax) 
    {
        xCoord = xCoord-(sliderValue-halfMax);
    }
else 
    {
        xCoord = xCoord + (halfMax-sliderValue);
    }
xCoord= xCoord + (642/sliderMaxMinDiff)*(sliderValue-sliderMin);
newB.frame = CGRectMake(xCoord,yCoord,84,47);

I have a slider with the minValue = 0 and maximumValue = 1000. I have a bubble on slider which runs with the thumb of the slider and displays the value of the slider.
But i am unable to run the bubble with the slider thumb.
Here's the code snippet:

CGFloat sliderMax = localSlider.maximumValue;
CGFloat sliderMin = localSlider.minimumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = _dsp;
CGFloat halfMax = (sliderMax+sliderMin)/2.0;
//int hMax = [halfMax intValue];
CGFloat xCoord = halfMax- 55.0;
CGFloat yCoord = (CGFloat)_positionX;
if (sliderValue > halfMax) 
    {
        xCoord = xCoord-(sliderValue-halfMax);
    }
else 
    {
        xCoord = xCoord + (halfMax-sliderValue);
    }
xCoord= xCoord + (642/sliderMaxMinDiff)*(sliderValue-sliderMin);
newB.frame = CGRectMake(xCoord,yCoord,84,47);

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

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

发布评论

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

评论(1

何止钟意 2024-11-15 01:59:51

@Ashutosh它可能有一些用处

-(void)sliderValueChanged:(id)sender{

    UISlider *slider = (UISlider*)sender;
    CGFloat sliderMin =  slider.minimumValue;
    CGFloat sliderMax = slider.maximumValue;
    CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
    CGFloat sliderValue = slider.value;

    if(sliderMin < 0.0) {

        sliderValue = slider.value-sliderMin;
        sliderMax = sliderMax - sliderMin;
        sliderMin = 0.0;
        sliderMaxMinDiff = sliderMax - sliderMin;
    }

    CGFloat xCoord = ((sliderValue-sliderMin)/sliderMaxMinDiff)*[slider frame].size.width-SLIDER_CALLOUT_WIDTH/2.0;

    CGFloat halfMax = (sliderMax+sliderMin)/2.0;

    if(sliderValue > halfMax) {

        sliderValue = (sliderValue - halfMax)+(sliderMin*1.0);
        sliderValue = sliderValue/halfMax;
        sliderValue = sliderValue*11.0;

        xCoord = xCoord - sliderValue;
    }

    else if(sliderValue <  halfMax) {

        sliderValue = (halfMax - sliderValue)+(sliderMin*1.0);
        sliderValue = sliderValue/halfMax;
        sliderValue = sliderValue*11.0;

        xCoord = xCoord + sliderValue;
    }
    int index = ceil(slider.value) ;


    if (MIN_INDEX<= index <=MAX_INDEX) {
        CGPoint callOutPoint = CGPointMake(xCoord, slider.frame.origin.y);
        //[self drawCallOutAtRect:callOutPoint andDate:[self.dataSourceArray objectAtIndex:(8-index)]];     
        //Call A Function To draw Bubble on Slider Top
    }   
    previousIndex = index;
}

你也可以从 https://github.com/elc/ELCSlider 获取一些提示

这是我制作的屏幕截图 在此处输入图像描述

我使用这些值添加了滑块-

UISlider *timeSliderObj = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
timeSliderObj.maximumValue = 8;
timeSliderObj.minimumValue = 1;
timeSliderObj.value = 8;

@Ashutosh It might be of some use

-(void)sliderValueChanged:(id)sender{

    UISlider *slider = (UISlider*)sender;
    CGFloat sliderMin =  slider.minimumValue;
    CGFloat sliderMax = slider.maximumValue;
    CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
    CGFloat sliderValue = slider.value;

    if(sliderMin < 0.0) {

        sliderValue = slider.value-sliderMin;
        sliderMax = sliderMax - sliderMin;
        sliderMin = 0.0;
        sliderMaxMinDiff = sliderMax - sliderMin;
    }

    CGFloat xCoord = ((sliderValue-sliderMin)/sliderMaxMinDiff)*[slider frame].size.width-SLIDER_CALLOUT_WIDTH/2.0;

    CGFloat halfMax = (sliderMax+sliderMin)/2.0;

    if(sliderValue > halfMax) {

        sliderValue = (sliderValue - halfMax)+(sliderMin*1.0);
        sliderValue = sliderValue/halfMax;
        sliderValue = sliderValue*11.0;

        xCoord = xCoord - sliderValue;
    }

    else if(sliderValue <  halfMax) {

        sliderValue = (halfMax - sliderValue)+(sliderMin*1.0);
        sliderValue = sliderValue/halfMax;
        sliderValue = sliderValue*11.0;

        xCoord = xCoord + sliderValue;
    }
    int index = ceil(slider.value) ;


    if (MIN_INDEX<= index <=MAX_INDEX) {
        CGPoint callOutPoint = CGPointMake(xCoord, slider.frame.origin.y);
        //[self drawCallOutAtRect:callOutPoint andDate:[self.dataSourceArray objectAtIndex:(8-index)]];     
        //Call A Function To draw Bubble on Slider Top
    }   
    previousIndex = index;
}

You can also take some hint from https://github.com/elc/ELCSlider

Here is a screen shot of what i made enter image description here

I added the slider using these values-

UISlider *timeSliderObj = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
timeSliderObj.maximumValue = 8;
timeSliderObj.minimumValue = 1;
timeSliderObj.value = 8;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文