Open felixdkatt opened 7 years ago
I noticed this is exactly the same issue that was closed AFTER i wrote it. However sometimes you want the sliders to touch with no gap. to indicate a single value. Say u wanted to display range of money but you also wanted to allow a single value. Can I achieve this with a gap greater than 0? example you want to search for a product that is a range is $0 - $100 but then you want to do another search for a product thats exactly $50 with the same control. Can you still do that with say a gap of 1. Without it saying $50 - $51?
I tried gapBetweenThumbs = 1.0 and it still displayed the same problem. Are you using gesture touches to slide each button? If so maybe you can check the tap or drag and make sure that the number of objects below the touch is always 1 if its greater than 1 then only drag the max not both ? Hope that makes sense.
I think i see the issue. In the code below it can set both to highlighted even though you really only want to move one of them.
Since they're both highlighted the continueTracking method will move both depending on the direction of the drag instead of just one.
You could do 2 checks.
override open func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { previouslocation = touch.location(in: self)
// set highlighted positions for lower and upper thumbs
if lowerThumbLayer.frame.contains(previouslocation) {
lowerThumbLayer.highlighted = true
}
if upperThumbLayer.frame.contains(previouslocation) {
upperThumbLayer.highlighted = true
}
///NEW
if upperThumbLayer.highlighted && lowerThumbLayer.highlighted{
if upperThumbLayer.maxPosition == maxValue {
upperThumbLayer.highlighted = false
}else{
lowerThumbLayer.highlighted = false
}
}
/////////
return lowerThumbLayer.highlighted || upperThumbLayer.highlighted
}
I tried it locally and verified this fixes the issue
override open func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { previouslocation = touch.location(in: self)
// set highlighted positions for lower and upper thumbs
if lowerThumbLayer.frame.contains(previouslocation) {
lowerThumbLayer.highlighted = true
}
if upperThumbLayer.frame.contains(previouslocation) {
upperThumbLayer.highlighted = true
}
if upperThumbLayer.highlighted && lowerThumbLayer.highlighted{
if upperValue == maximumValue {
upperThumbLayer.highlighted = false
}else{
lowerThumbLayer.highlighted = false
}
}
return lowerThumbLayer.highlighted || upperThumbLayer.highlighted
}
Sorry I didn't do a pull request let me know if you'd like me to or if you just want to change it yourself.