Skip to content

Commit 0933383

Browse files
author
Marco Abundo
committed
Updated
1 parent c9d5bea commit 0933383

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

SLTDoubleTapSegmentedControl.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SLTDoubleTapSegmentedControl"
3-
s.version = "1.0.2"
3+
s.version = "1.0.4"
44
s.summary = "A double-tap UISegmentedControl subclass. Each segment functions as a discrete double-tap button."
55
s.description = <<-DESC
66
A double-tap UISegmentedControl subclass. Each segment functions as a discrete double-tap button. Based on http://stackoverflow.com/questions/17652773/how-to-deselect-a-segment-in-segmented-control-button-permanently-till-its-click?lq=1

SLTDoubleTapSegmentedControl/SLTDoubleTapSegmentedControl.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class SLTDoubleTapSegmentedControl: UISegmentedControl {
5959
// MARK: Custom touch handling
6060

6161
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
62-
let previousSelectedSegmentIndex = selectedSegmentIndex
62+
let previousSelectedSegmentIndex = selectedSegmentIndex
6363

6464
super.touchesBegan(touches, with: event)
6565

@@ -73,4 +73,20 @@ public class SLTDoubleTapSegmentedControl: UISegmentedControl {
7373
sendActions(for: .valueChanged)
7474
}
7575
}
76+
77+
override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
78+
let previousSelectedSegmentIndex = selectedSegmentIndex
79+
80+
super.touchesEnded(touches, with: event)
81+
82+
if previousSelectedSegmentIndex == selectedSegmentIndex {
83+
// Clear the segmented control
84+
selectedSegmentIndex = UISegmentedControlNoSegment
85+
86+
// if the selectedSegmentIndex before the selection process is equal to the selectedSegmentIndex
87+
// after the selection process the superclass won't send a UIControlEventValueChanged event.
88+
// So we have to do this ourselves.
89+
sendActions(for: .valueChanged)
90+
}
91+
}
7692
}

0 commit comments

Comments
 (0)