Skip to content

Commit

Permalink
v. 1.1
Browse files Browse the repository at this point in the history
ValueChanged support on Tap
  • Loading branch information
Daniele authored and Daniele committed Aug 26, 2016
1 parent f232e9b commit a145a08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions Classes/G8SliderStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ class G8SliderStep: UISlider {
if self.highlighted {
return
}

let pointTapped: CGPoint = gestureRecognizer.locationInView(self)
let percentage = Float(pointTapped.x / trackWidth)
let delta = percentage * (maximumValue - minimumValue)
let newValue = minimumValue + delta

self.setValue(newValue, animated: false)
didMoveSliderStepValue()
didMoveSliderStepValue(true)
}

internal func movingSliderStepValue() {
Expand All @@ -86,14 +86,17 @@ class G8SliderStep: UISlider {
setThumbForSliderValue(floatValue)
}

internal func didMoveSliderStepValue() {
internal func didMoveSliderStepValue(sendValueChangedEvent: Bool = false) {
let intValue = Int(round(self.value))
let floatValue = Float(intValue)

UIView.animateWithDuration(0.15, animations: {
self.setValue(floatValue, animated: true)
}) { (fin) in
self.setThumbForSliderValue(floatValue)
if sendValueChangedEvent {
self.sendActionsForControlEvents(.ValueChanged)
}
}
}

Expand Down Expand Up @@ -137,7 +140,7 @@ class G8SliderStep: UISlider {
print("G8SliderStep ERROR: minimumValue AND maximumValue need to be UInt (not Float). EXIT.")
return
}

guard let images = stepImages where images.count == Int((maximumValue - minimumValue + 1)) else {
print("G8SliderStep ERROR: images is nil OR images.count != (maximumValue - minimumValue + 1). EXIT.")
return
Expand Down Expand Up @@ -178,7 +181,7 @@ class G8SliderStep: UISlider {
l.removeFromSuperview()
}
_stepTickLabels?.removeAll()

for index in 0..<ti.count {
let title = ti[index]
let lbl = UILabel()
Expand Down Expand Up @@ -314,12 +317,12 @@ class G8SliderStep: UISlider {

CGContextRestoreGState(ctx)
}

//Avoid exc bad access on viewcontroller view did load
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
drawTrack()
self.value = self.minimumValue
}

}
Binary file not shown.
4 changes: 2 additions & 2 deletions G8SliderStep/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down

0 comments on commit a145a08

Please sign in to comment.