Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handle jump when first move #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Pod/Classes/TTRangeSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ @interface TTRangeSlider ()
@property (nonatomic, assign) CGSize minLabelTextSize;
@property (nonatomic, assign) CGSize maxLabelTextSize;

@property (nonatomic, assign) CGFloat adjustDistance;

@property (nonatomic, strong) NSNumberFormatter *decimalNumberFormatter; // Used to format values if formatType is YLRangeSliderFormatTypeDecimal

// strong reference needed for UIAccessibilityContainer
Expand Down Expand Up @@ -365,14 +367,17 @@ - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {

if (distanceFromLeftHandle < distanceFromRightHandle && self.disableRange == NO){
self.leftHandleSelected = YES;
self.adjustDistance = gesturePressLocation.x - CGRectGetMidX(self.leftHandle.frame);
[self animateHandle:self.leftHandle withSelection:YES];
} else {
if (self.selectedMaximum == self.maxValue && [self getCentreOfRect:self.leftHandle.frame].x == [self getCentreOfRect:self.rightHandle.frame].x) {
self.leftHandleSelected = YES;
self.adjustDistance = gesturePressLocation.x - CGRectGetMidX(self.leftHandle.frame);
[self animateHandle:self.leftHandle withSelection:YES];
}
else {
self.rightHandleSelected = YES;
self.adjustDistance = gesturePressLocation.x - CGRectGetMidX(self.rightHandle.frame);
[self animateHandle:self.rightHandle withSelection:YES];
}
}
Expand Down Expand Up @@ -443,7 +448,7 @@ - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [touch locationInView:self];

//find out the percentage along the line we are in x coordinate terms (subtracting half the frames width to account for moving the middle of the handle, not the left hand side)
float percentage = ((location.x-CGRectGetMinX(self.sliderLine.frame)) - self.handleDiameter/2) / (CGRectGetMaxX(self.sliderLine.frame) - CGRectGetMinX(self.sliderLine.frame));
float percentage = ((location.x - _adjustDistance -CGRectGetMinX(self.sliderLine.frame))) / (CGRectGetMaxX(self.sliderLine.frame) - CGRectGetMinX(self.sliderLine.frame));

//multiply that percentage by self.maxValue to get the new selected minimum value
float selectedValue = percentage * (self.maxValue - self.minValue) + self.minValue;
Expand Down