Skip to content

Instantly share code, notes, and snippets.

View aybekckaya's full-sized avatar
🏠
Working from home

Aybek Can Kaya aybekckaya

🏠
Working from home
View GitHub Profile
import UIKit
class ChronometerVC: UIViewController {
private var displayLink:DisplayLink?
private let pulsatingLayer:CAShapeLayer = {
let path = UIBezierPath(arcCenter: .zero, radius: 100, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: true)
let layer = CAShapeLayer()
layer.path = path.cgPath
layer.strokeColor = UIColor.clear.cgColor
class ChronometerVC: UIViewController {
private var displayLink:DisplayLink?
private let lblCounter:UILabel = {
let lbl = UILabel()
lbl.font = UIFont(name: "Verdana", size: 28)
lbl.textAlignment = NSTextAlignment.center
lbl.textColor = UIColor.black
return lbl
}()
enum LikeGestureStatus {
case unknown
case fail
case success
}
class LikeGestureRecognizer:UIGestureRecognizer {
private var lastTouchTime:CFTimeInterval = CACurrentMediaTime()
private(set) var status = LikeGestureStatus.unknown
private(set) var doubleTapGestureThreshold:CFTimeInterval = 0.25
class LikeGestureRecognizer:UIGestureRecognizer {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesBegan(touches, with: event)
self.state = .began
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesMoved(touches, with: event)
self.state = .changed
override func viewDidLoad() {
super.viewDidLoad()
let likeGesture = LikeGestureRecognizer(target: self, action: #selector(handleLikeGesture(gesture:)))
self.viewGesture.addGestureRecognizer(likeGesture)
}
@objc private func handleLikeGesture(gesture:LikeGestureRecognizer) {
print("I never be called. You have to implement gesture recognizer's state setters")
}
class LikeGestureRecognizer:UIGestureRecognizer {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesBegan(touches, with: event)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesMoved(touches, with: event)
}
class TapGestureReplicator:UIGestureRecognizer {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
// Checking the count of touches .
// If number of finger used in gesture is not equal to one , then gesture should fail.
guard touches.count == 1 , let _ = touches.first else {
self.state = .failed
return
}
self.state = .began