Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Add getTouches demo
Browse files Browse the repository at this point in the history
  • Loading branch information
morizotter committed May 3, 2017
1 parent 2dfce5b commit bb878a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Example/Example/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class DetailViewController: UIViewController {

var text: String?

weak var timer: Timer?

@IBOutlet weak private var textLabel: UILabel!

override func viewDidLoad() {
Expand All @@ -20,4 +22,28 @@ class DetailViewController: UIViewController {
self.textLabel.text = "No.\(text) cell is tapped."
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

timer = Timer.scheduledTimer(timeInterval: 1.0/60.0, target: self, selector: #selector(logTouches(timer:)), userInfo: nil, repeats: true)
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

timer?.invalidate()
timer = nil
}

// Example for getting current touches
// * Caution: Touches here have been emmited before. For example `phase` is always `stationary`,
// it WAS `moved` at the time emmited.
// So use `getTouches` func for limited debug purpose.
// If you want to know the exact value, please override `handleEvent:` in UIWindow+Swizzle.swift.
func logTouches(timer: Timer) {
for (idx, touch) in Visualizer.getTouches().enumerated() {
print("[\(idx)] location: \(touch.location(in: self.view))")
}
}
}
2 changes: 1 addition & 1 deletion TouchVisualizer/Visualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension Visualizer {
return nil
}

public func handleEvent(_ event: UIEvent) {
open func handleEvent(_ event: UIEvent) {
if event.type != .touches {
return
}
Expand Down

0 comments on commit bb878a6

Please sign in to comment.