如何在双面滑块中将滑块设置为标记

时间:2014-04-25 10:18:32

标签: ios custom-controls uislider

我必须双面滑块才能获得最小值和最大值。

在最小和最大点之间也有标记,如下面的安排。

|--------|-----------|---------|

10      20          30        40  

当我拖动假想左边的nob在10-20之间然后如果valuse小于15然后自动动画/移动到10但是如果值大于15然后它自动移动/动画到20。

我很困惑如何移动/动画它。

我正在使用REDRangeSlider项目作为参考。

1 个答案:

答案 0 :(得分:1)

我已根据您的要求对代码进行了一些更改。请检查一下。

在分配init此控件时添加此方法。

[self.rangeSlider addTarget:self action:@selector(rangeSliderValueChanged:) forControlEvents:UIControlEventValueChanged];//This is already added.
[self.rangeSlider addTarget:self action:@selector(dragEnded:) forControlEvents:UIControlEventTouchUpOutside];//add this

实现此方法 - 拖动结束时将调用此方法。

-(void)dragEnded:(id)sender
{
    NSLog(@"called");
    //Set your Conditions this is for testing.
    if (self.rangeSlider.leftValue<15.0)
    {
        self.rangeSlider.leftValue = 10.0;
    }
}

在REDRangeSlider类中检查这两个处理Pan Gesture状态的方法,因此当你拖动end时,方法将调用此手势状态。那时调用你在主类中集成的动作。

- (void)leftHandlePanEngadged:(UIGestureRecognizer *)gesture 
{
    else if (panGesture.state == UIGestureRecognizerStateCancelled ||
         panGesture.state == UIGestureRecognizerStateEnded ||
         panGesture.state == UIGestureRecognizerStateCancelled) {
        self.leftHandle.highlighted = NO;
        self.leftValue = [self roundValueToStepValue:self.leftValue];
        //Change below line For Left .
        [self sendActionsForControlEvents:UIControlEventTouchUpOutside];
    }
}
- (void)rightHandlePanEngadged:(UIGestureRecognizer *)gesture 
{
    UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gesture;

     //Other code ........
    else if (panGesture.state == UIGestureRecognizerStateCancelled ||
         panGesture.state == UIGestureRecognizerStateEnded ||
         panGesture.state == UIGestureRecognizerStateCancelled) {
        self.rightHandle.highlighted = NO;
        self.rightValue = [self roundValueToStepValue:self.rightValue];
         //Change below line For right .
        [self sendActionsForControlEvents:UIControlEventTouchUpOutside];
    }
}