Last active
January 16, 2020 13:40
-
-
Save wata/f50d401a89b53e81b0a2a09f92c842b8 to your computer and use it in GitHub Desktop.
Touches shorter than 0.1 seconds are detected as a tap, and touches longer than 0.1 seconds are canceled.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
final class JustTapGestureRecognizer: UITapGestureRecognizer { | |
private var timer: Timer? | |
private let cancellationTimeInterval = TimeInterval(0.1) | |
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) { | |
timer = Timer.scheduledTimer(withTimeInterval: cancellationTimeInterval, repeats: false) { [weak self] (_) in | |
self?.state = .cancelled | |
} | |
super.touchesBegan(touches, with: event) | |
} | |
override func reset() { | |
timer?.invalidate() | |
timer = nil | |
super.reset() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment