Make sliders should be quantized. Issue #1342

This commit is contained in:
Maurice Parker
2019-11-24 09:41:50 -06:00
parent e05fdc99dd
commit 88707517e8
3 changed files with 57 additions and 9 deletions

View File

@@ -17,4 +17,11 @@ class CroppingPreviewParameters: UIPreviewParameters {
self.visiblePath = visiblePath
}
init(view: UIView, size: CGSize) {
super.init()
let newBounds = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let visiblePath = UIBezierPath(roundedRect: newBounds, cornerRadius: 10)
self.visiblePath = visiblePath
}
}

View File

@@ -13,9 +13,12 @@ class TickMarkSlider: UISlider {
private var enableFeedback = false
private let feedbackGenerator = UISelectionFeedbackGenerator()
private var roundedValue: Float?
override var value: Float {
didSet {
if enableFeedback && value.truncatingRemainder(dividingBy: 1) == 0 {
let testValue = value.rounded()
if testValue != roundedValue && enableFeedback && value.truncatingRemainder(dividingBy: 1) == 0 {
roundedValue = testValue
feedbackGenerator.selectionChanged()
}
}
@@ -66,6 +69,12 @@ class TickMarkSlider: UISlider {
}
}
override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
let result = super.continueTracking(touch, with: event)
value = value.rounded()
return result
}
override func endTracking(_ touch: UITouch?, with event: UIEvent?) {
value = value.rounded()