@@ -523,26 +523,49 @@ import UIKit
523
523
)
524
524
}
525
525
526
- public func changeLeftKnobPosition( position: CGFloat ) {
527
- let minValue = ( position - scaleMinValue) / scale
528
- leftKnob. xPositionConstraint. constant = bar. frame. width * minValue
529
- previousRangeSelectedValues = rangeSelectedCalculator. calculateRangeSelected (
530
- leftKnobPosition: leftKnob. xPositionConstraint. constant,
531
- rightKnobPosition: rightKnob. xPositionConstraint. constant,
532
- barWidth: bar. frame. width
533
- )
526
+ /**
527
+ Change the value of the left know programmatically.
528
+
529
+ - parameter value: the new value to be assigned to the left knob
530
+ */
531
+ public func changeLeftKnob( value: CGFloat ) {
532
+ if ( isValidForLeftKnob ( value: value) ) {
533
+ let minValue = ( value - scaleMinValue) / scale
534
+ leftKnob. xPositionConstraint. constant = bar. frame. width * minValue
535
+ previousRangeSelectedValues = rangeSelectedCalculator. calculateRangeSelected (
536
+ leftKnobPosition: leftKnob. xPositionConstraint. constant,
537
+ rightKnobPosition: rightKnob. xPositionConstraint. constant,
538
+ barWidth: bar. frame. width
539
+ )
540
+ }
534
541
}
535
-
536
- public func changeRightKnobPosition( position: CGFloat ) {
537
- let maxValue = ( position - scaleMinValue) / scale
538
- rightKnob. xPositionConstraint. constant = ( bar. frame. width * maxValue) - bar. frame. width
539
- previousRangeSelectedValues = rangeSelectedCalculator. calculateRangeSelected (
540
- leftKnobPosition: leftKnob. xPositionConstraint. constant,
541
- rightKnobPosition: rightKnob. xPositionConstraint. constant,
542
- barWidth: bar. frame. width
543
- )
542
+
543
+ /**
544
+ Change the value of the right know programmatically.
545
+
546
+ - parameter value: the new value to be assigned to the right knob
547
+ */
548
+ public func changeRightKnob( value: CGFloat ) {
549
+ if ( isValidforRightKnob ( value: value) ) {
550
+ let maxValue = ( value - scaleMinValue) / scale
551
+ rightKnob. xPositionConstraint. constant = ( bar. frame. width * maxValue) - bar. frame. width
552
+ previousRangeSelectedValues = rangeSelectedCalculator. calculateRangeSelected (
553
+ leftKnobPosition: leftKnob. xPositionConstraint. constant,
554
+ rightKnobPosition: rightKnob. xPositionConstraint. constant,
555
+ barWidth: bar. frame. width
556
+ )
557
+ }
544
558
}
545
-
559
+
560
+ private func isValidForLeftKnob( value: CGFloat ) -> Bool {
561
+ return value > scaleMinValue && value < previousRangeSelectedValues. maxValue
562
+ }
563
+
564
+
565
+ private func isValidforRightKnob( value: CGFloat ) -> Bool {
566
+ return value <= scaleMaxValue && value > previousRangeSelectedValues. minValue
567
+ }
568
+
546
569
private func setup( ) {
547
570
addSubview ( bar)
548
571
bar. addSubview ( selectedProgressView)
@@ -658,7 +681,7 @@ import UIKit
658
681
}
659
682
660
683
@objc final func moveLeftKnob( gestureRecognizer: UIPanGestureRecognizer ) {
661
- recognize ( gestureRecognizer: gestureRecognizer, updateKnob: updateLeftKnobPositionUsing)
684
+ recognize ( gestureRecognizer: gestureRecognizer, updateKnob: updateLeftKnobPositionUsing)
662
685
}
663
686
664
687
@objc final func moveRightKnob( gestureRecognizer: UIPanGestureRecognizer ) {
0 commit comments