Question

I have to double sided slider to get min and max value.

There is marker also in between min and max point like below arrangement.

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

10      20          30        40  

When i drag suppose left nob in between 10-20 then if valuse less than 15 then automatically animate/move to 10 but if value grater than 15 then it automatically move/animate to 20.

I am stuck at point how to move/animate it.

I am using REDRangeSlider project for reference.

Was it helpful?

Solution

I've done some changes in code as per your requirement. Please check this.

Add this method when you alloc init this control.

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

Implement this method -- this method will call when you drag end.

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

In REDRangeSlider Class Check this two methods which handle Pan Gesture states, so when you drag end then method will call this gesture state. at that time call this action which you integrate in your main class.

- (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];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top