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
// BannerView.swift
import UIKit
class BannerView: UIView , UIScrollViewDelegate{
private let scrollView:UIScrollView = {
let sc = UIScrollView(frame: .zero)
sc.translatesAutoresizingMaskIntoConstraints = false
sc.isPagingEnabled = true
extension UISpringTimingParameters {
public convenience init(dampingRatio: CGFloat, frequencyResponse: CGFloat) {
precondition(dampingRatio >= 0)
precondition(frequencyResponse > 0)
let mass = 1 as CGFloat
let stiffness = pow(2 * .pi / frequencyResponse, 2) * mass
let damping = 4 * .pi * dampingRatio * mass / frequencyResponse
self.init(mass: mass, stiffness: stiffness, damping: damping, initialVelocity: .zero)
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
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)
}
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)
self.state = .began
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesMoved(touches, with: event)
self.state = .changed
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