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
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) |
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
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 |
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
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) | |
} | |
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
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") | |
} |
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
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 |
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
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 |
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
var displayLink:CADisplayLink! | |
func setUpDisplayLink() { | |
displayLink = CADisplayLink(target: self, selector: #selector(update)) | |
displayLink.preferredFramesPerSecond = 60 // (optional) if you do not define , then device uses maxFramesPS | |
displayLink.add(to: .main, forMode: RunLoop.Mode.common) | |
} | |
@objc private func update() { | |
print("refresh : \(CACurrentMediaTime())") |
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
class PerformanceVC: UIViewController { | |
@IBOutlet weak var lblFramesPerSecond: UILabel! | |
@IBOutlet weak var lblTimeDifference: UILabel! | |
@IBOutlet weak var lblElapsedTime: UILabel! | |
@IBOutlet weak var lblActualFrames: UILabel! | |
private var latestTimeUpdated:CFTimeInterval = CACurrentMediaTime() | |
private var startedTime:CFTimeInterval = CACurrentMediaTime() | |
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 | |
class DisplayLink: NSObject { | |
private var displayLink:CADisplayLink! | |
private var startTime:CFTimeInterval = CACurrentMediaTime() | |
var displayLinkUpdated:((_ timeElapsed:CFTimeInterval)->())? | |
override init() { |