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

Generate editing DidBegin and DidEnd actions #41

Open
wants to merge 5 commits 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
44 changes: 30 additions & 14 deletions NMRangeSlider/NMRangeSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


#define IS_PRE_IOS7() (DeviceSystemMajorVersion() < 7)
NSUInteger DeviceSystemMajorVersion(void);

NSUInteger DeviceSystemMajorVersion() {
static NSUInteger _deviceSystemMajorVersion = -1;
Expand Down Expand Up @@ -450,10 +451,16 @@ - (CGRect)trackRect

float lowerHandleWidth = _lowerHandleHidden ? _lowerHandleHiddenWidth : _lowerHandle.frame.size.width;
float upperHandleWidth = _upperHandleHidden ? _upperHandleHiddenWidth : _upperHandle.frame.size.width;

float xLowerValue = ((self.bounds.size.width - lowerHandleWidth) * (_lowerValue - _minimumValue) / (_maximumValue - _minimumValue))+(lowerHandleWidth/2.0f);
float xUpperValue = ((self.bounds.size.width - upperHandleWidth) * (_upperValue - _minimumValue) / (_maximumValue - _minimumValue))+(upperHandleWidth/2.0f);


float xLowerValue = lowerHandleWidth/2.0f;
float xUpperValue = self.bounds.size.width - upperHandleWidth/2.0f;

if (_maximumValue != _minimumValue)
{
xLowerValue = ((self.bounds.size.width - lowerHandleWidth) * (_lowerValue - _minimumValue) / (_maximumValue - _minimumValue))+(lowerHandleWidth/2.0f);
xUpperValue = ((self.bounds.size.width - upperHandleWidth) * (_upperValue - _minimumValue) / (_maximumValue - _minimumValue))+(upperHandleWidth/2.0f);
}

retValue.origin = CGPointMake(xLowerValue, (self.bounds.size.height/2.0f) - (retValue.size.height/2.0f));
retValue.size.width = xUpperValue-xLowerValue;

Expand Down Expand Up @@ -503,7 +510,7 @@ -(CGRect) trackBackgroundRect
}

//returms the rect of the tumb image for a given track rect and value
- (CGRect)thumbRectForValue:(float)value image:(UIImage*) thumbImage
- (CGRect)thumbRectForValue:(float)value image:(UIImage*) thumbImage isLowerValue:(BOOL)isLowerValue
{
CGRect thumbRect;
UIEdgeInsets insets = thumbImage.capInsets;
Expand All @@ -514,8 +521,13 @@ - (CGRect)thumbRectForValue:(float)value image:(UIImage*) thumbImage
{
thumbRect.size.height=self.bounds.size.height;
}

float xValue = ((self.bounds.size.width-thumbRect.size.width)*((value - _minimumValue) / (_maximumValue - _minimumValue)));

float xValue = isLowerValue ? 0 : self.bounds.size.width - thumbRect.size.width;
if (_maximumValue != _minimumValue)
{
xValue = ((self.bounds.size.width-thumbRect.size.width)*((value - _minimumValue) / (_maximumValue - _minimumValue)));
}

thumbRect.origin = CGPointMake(xValue, (self.bounds.size.height/2.0f) - (thumbRect.size.height/2.0f));

return CGRectIntegral(thumbRect);
Expand All @@ -539,12 +551,12 @@ - (void) addSubviews
//------------------------------
// Lower Handle Handle
self.lowerHandle = [[UIImageView alloc] initWithImage:self.lowerHandleImageNormal highlightedImage:self.lowerHandleImageHighlighted];
self.lowerHandle.frame = [self thumbRectForValue:_lowerValue image:self.lowerHandleImageNormal];
self.lowerHandle.frame = [self thumbRectForValue:_lowerValue image:self.lowerHandleImageNormal isLowerValue:YES];

//------------------------------
// Upper Handle Handle
self.upperHandle = [[UIImageView alloc] initWithImage:self.upperHandleImageNormal highlightedImage:self.upperHandleImageHighlighted];
self.upperHandle.frame = [self thumbRectForValue:_upperValue image:self.upperHandleImageNormal];
self.upperHandle.frame = [self thumbRectForValue:_upperValue image:self.upperHandleImageNormal isLowerValue:NO];

//------------------------------
// Track Brackground
Expand Down Expand Up @@ -577,13 +589,13 @@ -(void)layoutSubviews
self.track.image = [self trackImageForCurrentValues];

// Layout the lower handle
self.lowerHandle.frame = [self thumbRectForValue:_lowerValue image:self.lowerHandleImageNormal];
self.lowerHandle.frame = [self thumbRectForValue:_lowerValue image:self.lowerHandleImageNormal isLowerValue:YES];
self.lowerHandle.image = self.lowerHandleImageNormal;
self.lowerHandle.highlightedImage = self.lowerHandleImageHighlighted;
self.lowerHandle.hidden = self.lowerHandleHidden;

// Layoput the upper handle
self.upperHandle.frame = [self thumbRectForValue:_upperValue image:self.upperHandleImageNormal];
self.upperHandle.frame = [self thumbRectForValue:_upperValue image:self.upperHandleImageNormal isLowerValue:NO];
self.upperHandle.image = self.upperHandleImageNormal;
self.upperHandle.highlightedImage = self.upperHandleImageHighlighted;
self.upperHandle.hidden= self.upperHandleHidden;
Expand Down Expand Up @@ -621,7 +633,10 @@ -(BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
}

_stepValueInternal= _stepValueContinuously ? _stepValue : 0.0f;



[self sendActionsForControlEvents:UIControlEventEditingDidBegin];

return YES;
}

Expand Down Expand Up @@ -700,8 +715,9 @@ -(void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
[self setLowerValue:_lowerValue animated:YES];
[self setUpperValue:_upperValue animated:YES];
}

[self sendActionsForControlEvents:UIControlEventValueChanged];

[self sendActionsForControlEvents:UIControlEventValueChanged];
[self sendActionsForControlEvents:UIControlEventEditingDidEnd];
}

@end