HamzaGhazouani / HGCircularSlider

A custom reusable circular / progress slider control for iOS application.
MIT License
2.6k stars 278 forks source link

open some function to allow override newValue method #41

Closed huuthanhla closed 5 years ago

huuthanhla commented 5 years ago

Allow override this method:

CircularSlider.newValue(from oldValue: CGFloat, touch touchPosition: CGPoint, start startPosition: CGPoint) -> CGFloat

(#line 302 in CircularSlider.swift)

HamzaGhazouani commented 5 years ago

Hi @thanhlazio, thanks for your contribution, I'm not sure that it will be a good idea, to make all this properties public, can you give an example/ usecase of this need ?

huuthanhla commented 5 years ago

Hi @HamzaGhazouani I need to track slider in min and max range, like this:

    override func newValue(from oldValue: CGFloat, touch touchPosition: CGPoint, start startPosition: CGPoint) -> CGFloat {

        let angle = CircularSliderHelper.angle(betweenFirstPoint: startPosition, secondPoint: touchPosition, inCircleWithCenter: bounds.center)
        let interval = Interval(min: minimumValue, max: maximumValue, rounds: numberOfRounds)
        let deltaValue = CircularSliderHelper.delta(in: interval, for: angle, oldValue: oldValue)

        var newValue = oldValue + deltaValue

//        let range = maximumValue - minimumValue
//        
//        if newValue > maximumValue {
//            newValue -= range
//        }
//        else if newValue < minimumValue {
//            newValue += range
//        }

        /// Only tracking between min and max
        if newValue > maximumValue {
            newValue = maximumValue - 0.1
        } else if newValue < minimumValue {
            newValue = minimumValue
        }

        return newValue
    }

Otherwise, can you add the tracking variable to apply that logic, thank you!